home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d19 / ansi_f.arc / ANSI.ASM next >
Assembly Source File  |  1990-12-11  |  102KB  |  1,908 lines

  1. ;------------------------------------------------------------------------;
  2. ;  ANSI.COM - Replacement for the ANSI.SYS console device driver.        ;
  3. ;  Unlike ANSI.SYS which must be installed at boot time, ANSI.COM        ;
  4. ;  can be installed and uninstalled at anytime.  Enhancements include    ;
  5. ;  a fast screen write and variable sized keyboard reassignment buffer.  ;
  6. ;                                                                        ;
  7. ;  Update 3/2/89 - Fix for DOS function 0Bh, Check Standard Input Status ;
  8. ;                      and STDIN in ANSI_INT_21 handler.                 ;
  9. ;                  Leading zero inserted for Device Status Report for    ;
  10. ;                      single digit cursor positions.                    ;
  11. ;                  INFORMATION typo 40 for 40H.                          ;
  12. ;                  WRITE_FAST modified to handle CR and LF instead of    ;
  13. ;                      WRITE_CHAR.                                       ;
  14. ;  Update 3/7/89 - Fix for CLS in graphics mode.          Version 1.2    ;
  15. ;                                                                        ;
  16. ;  Update 8/8/89 - STI added to INT 21 and 29 handler.    Version 1.3    ;
  17. ;:                                                                       ;
  18. ;: Update 01/01/90 - [KON | KOFF] and [PON | POFF] added  Version 1.31   ;
  19. ;:                   (all changes marked with ;: - Gary Meeker)          ;
  20. ;| Update 03/23/90 - /Q option added for no output when exectued  1.32   ;
  21. ;|                   (all changes marked with ;| - Gary Meeker)          ;
  22. ;; Update 05/16/90 - removed Syntax from output unless needed     1.33   ;
  23. ;;                   added /T test for load.                             ;
  24. ;;                   (all changes marked with ;; - Gary Meeker)          ;
  25. ;. Update 10/28/90 - Added /P nn top of screen protection mode    1.34   ;
  26. ;.                   (all changes marked with ;. - Gary Meeker)          ;
  27. ;@ Update 12/01/90 - Added PCBoard @X## color code support        1.35   ;
  28. ;@                   also added @Variable@ Support                       ;
  29. ;@                   added /S to load stats data from file               ;
  30. ;@                   (all changes marked with ;@ - Gary Meeker)          ;
  31. ;&                                                                       ;
  32. ;& Update 12/12/90 - My mistake, I didn't realize @X00 saved      1.36   ;
  33. ;&                   the color and @XFF restored it. Works now.          ;
  34. ;&                   Also made prompts return to start of line           ;
  35. ;&                   when cleared (like PCBoard does) & QON              ;
  36. ;&                   now changes @MORE@ & @PAUSE@ into @WAIT@            ;
  37. ;&                   (all changes marked with ;& - Gary Meeker)          ;
  38. ;                                                                        ;
  39. ;  PC Magazine - Michael J. Mefford                                      ;
  40. ;------------------------------------------------------------------------;
  41.  
  42. _TEXT          SEGMENT PUBLIC 'CODE'
  43.                ASSUME  CS:_TEXT,DS:_TEXT,ES:_TEXT,SS:_TEXT
  44.                ORG     100H
  45. START:         JMP     INITIALIZE
  46.  
  47. ;                 DATA AREA
  48. SIGNATURE      DB      CR,SPACE,SPACE,SPACE,CR,LF
  49. COPYRIGHT      DB      "ANSI 1.3f (C) 1988 Ziff Communications Co.",CR,LF    ;.
  50. PROGRAMMER     DB      "PC Magazine ",BOX," Michael J. Mefford",CR,LF,LF,"$"
  51.                DB      CTRL_Z
  52.  
  53. CR             EQU     13
  54. LF             EQU     10
  55. CTRL_Z         EQU     26
  56. SPACE          EQU     32
  57. BOX            EQU     254
  58. ESC_CHAR       EQU     27
  59. SINGLE_QUOTE   EQU     39
  60. DOUBLE_QUOTE   EQU     34
  61. BELL           EQU     7
  62. BS             EQU     8
  63. TAB            EQU     9
  64.  
  65. OFF            EQU     1
  66. ON             EQU     2
  67. SLOW           EQU     4
  68. FAST           EQU     8
  69. KOFF           EQU     16                         ;:
  70. KON            EQU     32                         ;:
  71. POFF           EQU     64                         ;:
  72. PON            EQU     128                        ;:
  73. STATUS_MASK    EQU     1111110000000001B          ;: Set Mask and Bit
  74.  
  75. ANSI_STATE     DW      ESC_STATE
  76. STATUS         DB      ON OR FAST OR KON OR PON           ;:
  77. PARAMETERS     DB      "OFF",0,"ON",0,0,"SLOWFASTKOFFKON",0,"POFFPON",0 ;:
  78. LAST_PARAMETER EQU     $ - PARAMETERS
  79.  
  80. OLD_INT_29     DW      ?,?
  81. OLD_INT_16     DW      ?,?
  82. OLD_INT_21     DW      ?,?
  83. OLD_INT_08     DW      ?,?              ;@ Save Timer Interupt
  84.  
  85. ATTRIBUTE      DB      7
  86. SAVE_ATTRIBUTE DB      ?                ;& For saving attribute
  87. SAVE_POSITION  DW      0
  88. LINE_WRAP      DB      ON
  89. QUOTE_TYPE     DB      ?
  90. ESC_COUNT      DW      0
  91. NUMBER_COUNT   DW      0
  92.  
  93. COMMAND_TABLE  LABEL   BYTE
  94. DB   "H", "A", "B", "C", "D", "f", "n", "s", "u", "K", "m", "h", "l", "p", "J"
  95. COMMAND_LENGTH EQU     $ - COMMAND_TABLE
  96.  
  97. DW   CURS_POSITION, CURSOR_UP,     CURSOR_DOWN, CURS_FORWARD, CURS_BACKWARD
  98. DW   HORZ_VERT_POS, DEVICE_STATUS, SAVE_CURSOR, RESTORE_CURS, ERASE_IN_LINE
  99. DW   SGR,           SET_MODE,      RESET_MODE,  REASSIGNMENT, CLS
  100. COMMAND_END    EQU     $ - 2
  101.  
  102. ATTRIBUTE_TABLE        LABEL    BYTE
  103. DB   00,01,04,05,07,08,30,31,32,33,34,35,36,37,40,41,42,43,44,45,46,47
  104. ATTRIBUTE_LENGTH       EQU      $ - ATTRIBUTE_TABLE
  105.  
  106. ;Format: AND mask,OR mask
  107. DB      000H,07H, 0FFH,08H, 0F8H,01H, 0FFH,80H, 0F8H,70H, 088H,00H
  108. DB      0F8H,00H, 0F8H,04H, 0F8H,02H, 0F8H,06H, 0F8H,01H, 0F8H,05H
  109. DB      0F8H,03H, 0F8H,07H, 08FH,00H, 08FH,40H, 08FH,20H, 08FH,60H
  110. DB      08FH,10H, 08FH,50H, 08FH,30H, 08FH,70H
  111. ATTRIBUTE_END          EQU      $ - 2
  112.  
  113. AT_VARIABLE_TABLE      LABEL BYTE                                          ;@
  114. DB   '@CLS@CLREOL@AUTOMORE@POFF@PON@QOFF@QON@BEEP@MORE@PAUSE@WAIT@HANGUP@' ;@
  115. DB   'OPTEXT@FIRSTU@FIRST@USER@CITY@HOMEPHONE@DATAPHONE@PROLTR@PRODESC@'   ;@
  116. DB   'EXPDATE@LASTDATEON@LASTTIMEON@INCONF@CONFNAME@BOARDNAME@'            ;@
  117. DB   'LASTCALLERNODE@LASTCALLERSYSTEM@EVENT@SYSOPIN@SYSOPOUT@BPS@NODE@'    ;@
  118. DB   'SYSDATE@SYSTIME@FILERATIO@BYTERATIO@'                                ;@
  119. DB   'SECURITY@NUMCALLS@NUMTIMESON@TIMELEFT@TIMELIMIT@TIMEUSED@TOTALTIME@' ;@
  120. DB   'BYTESLEFT@BYTELIMIT@DLFILES@UPFILES@KBLEFT@KBLIMIT@CONFNUM@'         ;@
  121. DB   'CURMSGNUM@HIGHMSGNUM@LOWMSGNUM@MSGREAD@MSGLEFT@NUMBLT@NUMDIR@'       ;@
  122. DB   'DAYBYTES@MINLEFT@DLBYTES@UPBYTES@EXPDAYS@'                           ;@
  123.  
  124. LAST_VARIABLE          EQU     $ - 1                                       ;@
  125.  
  126. JUMP_TABLE             LABEL WORD                                          ;@
  127. DW      CLS, ERASE_IN_LINE, AUTOMORE, AUTOOFF, AUTOOFF, QOFF, QON        ;&;@
  128. DW      BEEP, MORE, PAUSE, WAIT1, SKIP_IT                                  ;@
  129.  
  130. SUB_TABLE              LABEL BYTE                                          ;@
  131. DB      8,15,15,25,24,13,13,1,47                                           ;@
  132. DB      8,8,5,33,13,63                                                     ;@
  133. DB      52,52,5,5,5,5,2                                                    ;@
  134. DB      0,0,4,4                                                            ;@
  135. DB      2,4,2,2,2,2,2                                                      ;@
  136. DB      4,4,2,2,4,4,2                                                      ;@
  137. DB      4,4,4,4,4,2,2                                                      ;@
  138. DB      4,2,4,4,2                                                          ;@
  139.  
  140. SUB_LIST               LABEL BYTE                      ;@
  141. DB     '!OPTEXT!'                                      ;@ OPTTEXT
  142. DB     'GARY',0,0,0,0,0,0,0,0,0,0,0                    ;@ FirstU
  143. DB     'Gary',0,0,0,0,0,0,0,0,0,0,0                    ;@ First
  144. DB     'GARY MEEKER',0,0,0,0,0,0,0,0,0,0,0,0,0,0       ;@ User
  145. DB     'LAWRENCEVILLE, GA',0,0,0,0,0,0,0               ;@ City
  146. DB     '404 995-2699',0                                ;@ HomePhone
  147. DB     '404 962-1788',0                                ;@ DataPhone
  148. DB     'Z'                                             ;@ Proltr
  149. DB     'Zmodem       (Batch U/L and D/L)', 15 DUP (0)  ;@ ProDesc
  150. DB     '01-01-91'                                      ;@ ExpDate
  151. DB     '12-01-90'                                      ;@ LastDateOn
  152. DB     '08:00'                                         ;@ LastTimeOn
  153. DB     'Magazine (1) Conference ',0,0,0,0,0,0,0,0,0    ;@ InConf
  154. DB     'Magazine',0,0,0,0,0                            ;@ ConfName
  155. DB     'SHARP Technical Support Line BBS', 31 DUP (0)  ;@ BoardName
  156. DB     'MIKE BATE (RIVERDALE, GA)', 27 DUP (0)         ;@ LastCallerNode
  157. DB     'GARY MEEKER (LAWRENCEVILLE, GA)', 21 DUP (0)   ;@ LastCallerSystem
  158. DB     '04:30'                                         ;@ Event
  159. DB     '08:30'                                         ;@ SysopIn
  160. DB     '17:00'                                         ;@ SysopOut
  161. DB     '2400',0                                        ;@ bps
  162. DB     '1',0                                           ;@ Node
  163.  
  164. DD     48                                              ;@ FileRatio
  165. DD     128                                             ;@ ByteRatio
  166.  
  167. DW         120                                         ;@ Security
  168. DD       23946                                         ;@ numcalls
  169. DW        2107                                         ;@ numtimeson
  170. DW          61                                         ;@ timeleft
  171. DW         121                                         ;@ timelimit
  172. DW          59                                         ;@ timeused
  173. DW          59                                         ;@ totaltime
  174. DD     9508313                                         ;@ bytesleft
  175. DD    10238976                                         ;@ bytelimit
  176. DW          44                                         ;@ dlfiles
  177. DW        1234                                         ;@ upfiles
  178. DD        9285                                         ;@ KBLeft
  179. DD        9999                                         ;@ KBLimit
  180. DW           1                                         ;@ ConfNum
  181. DD        4734                                         ;@ CurMsgNum
  182. DD        4745                                         ;@ HighMsgNum
  183. DD           2                                         ;@ LowMsgNum
  184. DD        3456                                         ;@ MsgRead
  185. DD         987                                         ;@ MsgLeft
  186. DW          20                                         ;@ NumBlt
  187. DW          31                                         ;@ NumDir
  188. DD       30663                                         ;@ DayBytes
  189. DW          61                                         ;@ MinLeft
  190. DD      730663                                         ;@ DLBytes
  191. DD    12345678                                         ;@ UpBytes
  192. DW           0                                         ;@ ExpDays
  193. SUB_LENGTH     EQU      $ - SUB_LIST
  194.  
  195. PAUSE_TIMER    DW      182                             ;@
  196. PAUSE_DELAY    DW      182                             ;@ 10 Seconds
  197. MORE_DELAY     DW      182 * 12                        ;@ 2 Minute
  198. WAIT_DELAY     DW      182 * 12                        ;@ 2 Minute
  199.  
  200. WAIT_PROMPT    DB      'press enter to continue'       ;@
  201. WAIT_LENGTH    DW      $ - WAIT_PROMPT                 ;@
  202. MORE_PROMPT    DB      '(61 min left), (H)elp, More?'  ;@
  203. MORE_LENGTH    DW      $ - MORE_PROMPT                 ;@
  204. COMMA          DB      0                               ;@
  205. Q_STATE        DB      0                               ;&
  206.  
  207. BIOS_ACTIVE_PAGE       EQU     62H
  208. ACTIVE_PAGE    DB      ?
  209. ADDR_6845      DW      ?
  210. BIOS_CRT_MODE          EQU     49H
  211. CRT_MODE       DB      ?
  212. CRT_COLS       DW      ?
  213. CRT_LEN        DW      ?
  214. CRT_START      DW      ?
  215. CRT_DATA_LENGTH        EQU     $ - CRT_MODE
  216. CURSOR_POSN    LABEL   WORD
  217. CURSOR_COL     DB      ?
  218. CURSOR_ROW     DB      ?
  219. CRT_ROWS       DB      ?
  220.  
  221. START_SCROLL   DB      0       ;. Number of rows to protect from scrolling up
  222.  
  223. DOS_INPUT      DB      OFF
  224. BUSY_FLAG      DB      OFF
  225. REASSIGN_FLAG  DB      OFF
  226. REMOVE_FLAG    DB      ON
  227. REASSIGN_COUNT DW      0
  228. REASSIGN_POS   DW      ?
  229. FUNCTION_16    DB      ?
  230. ZR             EQU     1000000B
  231.  
  232. ESC_BUFFER_SIZE      EQU     126
  233. REASSIGNMENT_DEFAULT EQU     200
  234. REASSIGNMENT_SIZE    DW      REASSIGNMENT_DEFAULT
  235. REASSIGNMENT_MAX     EQU     60 * 1024
  236. REASSIGN_END         DW      REASSIGNMENT_BUFFER
  237. BUFFER_END           DW      REASSIGNMENT_BUFFER + REASSIGNMENT_DEFAULT
  238.  
  239. ;                   CODE AREA
  240. ;************* INTERRUPT HANDLERS *************;
  241. ;------------------------------------------------------------------------------;
  242. ; INT 29 is an undocumented interrupt called by DOS for output to the console. ;
  243. ;------------------------------------------------------------------------------;
  244.  
  245. ANSI_INT_29    PROC    FAR
  246.                STI
  247.                PUSH    AX                      ;Save all registers.
  248.                PUSH    BX
  249.                PUSH    CX
  250.                PUSH    DX
  251.                PUSH    SI
  252.                PUSH    DI
  253.                PUSH    DS
  254.                PUSH    ES
  255.                PUSH    BP
  256.  
  257.                CLD                             ;All string operations forward.
  258.                MOV     BX,CS                   ;Point to our data segment.
  259.                MOV     DS,BX
  260.                MOV     ES,BX
  261.                CALL    ANSI_STATE              ;Call the current state of
  262.                                                ; the ANSI Esc sequence.
  263.                POP     BP
  264.                POP     ES
  265.                POP     DS
  266.                POP     DI
  267.                POP     SI
  268.                POP     DX
  269.                POP     CX
  270.                POP     BX
  271.                POP     AX                      ;Restore all registers and
  272.                IRET                            ; and return
  273. ANSI_INT_29    ENDP
  274.  
  275. ;------------------------------------------------;
  276.  
  277. ANSI_INT_21    PROC    FAR
  278.                PUSHF
  279.                CMP     AH,0BH                  ;If DOS function 0Bh (Check
  280.                JNZ     CK_INPUT                ; Standard Input Status)
  281.                CMP     CS:REASSIGN_FLAG,ON     ; and reassignment in progress,
  282.                JNZ     CK_INPUT                ; including a Device Status
  283.                CALL    DWORD PTR CS:OLD_INT_21 ; Request, then process call in
  284.                MOV     AL,0FFH                 ; case control break pressed;
  285.                IRET                            ; then return 0FFh for char ready
  286.  
  287. CK_INPUT:      CMP     AH,3FH                  ;Read from STDIN?
  288.                JNZ     CK_CONSOLE
  289.                OR      BX,BX
  290.                JZ      INPUT
  291.  
  292. CK_CONSOLE:    CMP     AH,0AH                  ;If DOS Int 21 functions Ah,
  293.                JZ      INPUT                   ; 7h, 1h or console input (6h)
  294.                CMP     AH,7                    ; then tell INT 16, DOS input
  295.                JZ      INPUT                   ; is active.
  296.                CMP     AH,1
  297.                JZ      INPUT
  298.                CMP     AH,8
  299.                JZ      INPUT
  300.                CMP     AH,6
  301.                JNZ     QUICK21_EXIT
  302.                CMP     DL,0FFH
  303.                JZ      INPUT
  304. QUICK21_EXIT:  POPF                              ;If not, let the original
  305.                JMP     DWORD PTR CS:OLD_INT_21   ; interrupt process the call.
  306.  
  307. INPUT:         POPF
  308.                MOV     CS:DOS_INPUT,ON           ;INT 16 handler flag.
  309.                PUSHF
  310.                CALL    DWORD PTR CS:OLD_INT_21   ;Emulate an interrupt.
  311.                MOV     CS:DOS_INPUT,OFF          ;Turn flag back off.
  312.                STI
  313.                RET     2                         ;Return with current flags.
  314. ANSI_INT_21    ENDP
  315.  
  316. ;-----------------------------------------------------------------;
  317. ; If we get here via a DOS console input call, any awaiting key   ;
  318. ; in keyboard buffer is checked to see if it is to be reassigned. :
  319. ;-----------------------------------------------------------------;
  320.  
  321. ANSI_INT_16    PROC    FAR
  322.                STI                             ;Interrupts back on.
  323.                PUSHF                           ;Preserve flags on stack.
  324.                PUSH    BP
  325.                PUSH    DS
  326.                PUSH    AX
  327.                PUSH    CS                      ;Point to our data.
  328.                POP     DS
  329.  
  330.                CMP     DOS_INPUT,OFF           ;If not called via a DOS
  331.                JZ      QUICK16_EXIT            ; console input call, exit.
  332.                CMP     BUSY_FLAG,ON            ;If already processing a call,
  333.                JZ      QUICK16_EXIT            ; exit.
  334.                CLD                             ;All string operations forward.
  335.                MOV     BP,SP                   ;Base reference to flags on stack
  336.                MOV     FUNCTION_16,AH          ;Save function request.
  337.                AND     AH,NOT 10H              ;Strip possible extended request.
  338.                JZ      GET_KEY                 ;If zero, it's wait for a key.
  339.                DEC     AH                      ;Else, decrement.  If zero it's
  340.                JZ      KEY_STATUS              ; key status, else exit.
  341.  
  342. QUICK16_EXIT:  POP     AX                      ;Restore registers and let
  343.                POP     DS                      ; original interrupt handler
  344.                POP     BP                      ; process the call.
  345.                POPF
  346.                JMP     DWORD PTR CS:OLD_INT_16
  347.  
  348. KEY_STATUS:    OR      BYTE PTR [BP+6],ZR      ;Assume none ready; ZR = 1.
  349. GET_KEY:       MOV     BUSY_FLAG,ON            ;Non-reentrant; flag busy.
  350.                POP     AX
  351.                PUSH    BX                      ;Save some more registers.
  352.                PUSH    CX
  353.                PUSH    DX
  354.                PUSH    SI
  355.                PUSH    DI
  356.                CMP     REASSIGN_FLAG,ON        ;Already in process of reassign?
  357.                JZ      CK_BUFFER               ;If yes, check kbd buffer.
  358.  
  359.                PUSHF                           ;Else, emulate an interrupt.
  360.                CALL    DWORD PTR OLD_INT_16
  361.                PUSHF                           ;Status call results in flags.
  362.                TEST    FUNCTION_16,1           ;Was it a status call?
  363.                JZ      CK_DUP                  ;If no, check key returned.
  364.                POPF                            ;Else, retrieve status results.
  365.                JZ      INT16_EXIT              ;If zero, no key waiting.
  366.                AND     BYTE PTR [BP+6],NOT ZR  ;Else, ZR = 0.
  367.                PUSHF                           ;PUSHF just to keep stack right.
  368.  
  369. CK_DUP:        POPF                            ;Fix stack.
  370.                TEST    STATUS,KOFF             ;:If KOFF then we don't do
  371.                JNZ     INT16_EXIT              ;:re-assignments
  372.                MOV     BX,AX                   ;Match procedure wants key in BX.
  373.                CALL    CK_MATCH                ;Check reassignment buffer.
  374.                JC      INT16_EXIT              ;If no match, exit.
  375.                MOV     AX,[DI]                 ;Else, retrieve string length.
  376.                SUB     AX,3                    ;Adjust for length word and match
  377.                ADD     DI,3                    ; byte; same for string pointer.
  378.                OR      BL,BL                   ;Extended key? ie. key = 0.
  379.                JNZ     STORE_COUNT             ;If no, save length and pointer.
  380.                DEC     AX                      ;Else, adjust for extended code.
  381.                INC     DI
  382. STORE_COUNT:   MOV     REASSIGN_COUNT,AX       ;Save string length.
  383.                MOV     REASSIGN_POS,DI         ;Save pointer to string.
  384.                MOV     REASSIGN_FLAG,ON        ;Flag that replacement in effect.
  385. CK_BUFFER:     TEST    FUNCTION_16,1           ;Was it a key wait function call?
  386.                JNZ     RETRIEVE                ;If no, key status; get it.
  387.                CMP     REMOVE_FLAG,OFF         ;Removed it from kbd buffer?
  388.                JZ      RETRIEVE                ;If yes, get reassignment.
  389.                MOV     AH,FUNCTION_16          ;Else, eat the replaced character
  390.                INT     16H                     ; via INT 16.
  391.                MOV     REMOVE_FLAG,OFF         ;Flag character eaten.
  392.  
  393. RETRIEVE:      MOV     DI,REASSIGN_POS         ;Retrieve pointer to string.
  394.                MOV     AX,[DI]                 ;Retrieve replacement character.
  395.                TEST    FUNCTION_16,1           ;Is it a key wait function call?
  396.                JZ      REMOVE                  ;If yes, bump pointer up one.
  397.                AND     BYTE PTR [BP+6],NOT ZR  ;If no, status call; ZR = 0
  398.                JMP     SHORT INT16_EXIT        ;All done.
  399.  
  400. REMOVE:        INC     REASSIGN_POS            ;Move pointer to next character.
  401.                DEC     REASSIGN_COUNT          ;One less character to replace.
  402.                JZ      REASSIGN_DONE           ;If end of string, reset flags.
  403.                OR      AL,AL                   ;Else, extended replacement?
  404.                JNZ     INT16_EXIT              ;If no, done here.
  405.                INC     REASSIGN_POS            ;Else adjust pointers.
  406.                DEC     REASSIGN_COUNT
  407.                JNZ     INT16_EXIT              ;End of string?
  408. REASSIGN_DONE: MOV     REASSIGN_FLAG,OFF       ;If yes, reset flags.
  409.                MOV     REMOVE_FLAG,ON
  410.  
  411. INT16_EXIT:    MOV     BUSY_FLAG,OFF           ;Reset the busy flag.
  412.                POP     DI                      ;Restore registers.
  413.                POP     SI
  414.                POP     DX
  415.                POP     CX
  416.                POP     BX
  417.                POP     DS
  418.                POP     BP
  419.                POPF                            ;Flags on stack have status
  420.                RET     2                       ; results; kill old flags.
  421. ANSI_INT_16    ENDP
  422.  
  423. ANSI_INT_08    PROC    FAR
  424.                CMP     CS:[PAUSE_TIMER],0
  425.                JE      SKIP_TIMER
  426.                DEC     CS:[PAUSE_TIMER]
  427. SKIP_TIMER:    JMP     DWORD PTR CS:OLD_INT_08
  428. ANSI_INT_08    ENDP
  429.  
  430. ;************* ANSI ESCAPE STATE ROUTINES ************* ;
  431.  
  432. ESC_STATE:     MOV     BX,OFFSET BRACKET_STATE ;Assume Esc character.
  433.                CMP     AL,ESC_CHAR             ;Is it Esc?  If yes, store
  434.                JZ      SHORT_JUMP              ; char. and next state.
  435.                CMP     DOS_INPUT,ON            ;@ Called via DOS Input?
  436.                JE      WRITE_CHAR2             ;@ Yes, Nevermind
  437.                MOV     BX,OFFSET ATX_STATE     ;@ No, Assume @ Character
  438.                CMP     AL,"@"                  ;@ Is it @? If yes, store
  439.                JZ      SHORT_JUMP              ;@ char. and next state.
  440. WRITE_CHAR2:   JMP     WRITE_CHAR              ;@ Else, normal char; write it.
  441.  
  442. ;------------------------------------------------;
  443.  
  444. BRACKET_STATE: MOV     BX,OFFSET SPECIAL_STATE ;Assume left bracket.
  445.                CMP     AL,"["                  ;Is it left bracket?  If yes,
  446. SHORT_JUMP:    JZ      STORE_STATE             ;store char. and next state.
  447.                JMP     FLUSH_BUFFER            ;Else, flush Esc out of buffer.
  448.  
  449. ;---------------------------------------------------------------;
  450. ; Must process <ESC>[2J (CLS) regardless if ANSI.COM ON or OFF. ;
  451. ;---------------------------------------------------------------;
  452.  
  453. SPECIAL_STATE: MOV     BX,OFFSET CLS_STATE     ;Assume Erase in Display code.
  454.                CMP     AL,"2"                  ;Is it the "2" ?
  455.                JZ      STORE_STATE             ;If yes, progress to next state.
  456.                TEST    STATUS,OFF              ;Else, is ANSI OFF ?
  457.                JNZ     FLUSH_BUFFER            ;If yes, flush Esc, bracket.
  458.                MOV     BX,OFFSET PARAM_STATE   ;Else, check for first Set,
  459.                CMP     AL,"="                  ; Reset Mode characters of
  460.                JZ      STORE_STATE             ; "=" and "?".
  461.                CMP     AL,"?"
  462.                JZ      STORE_STATE             ;If found, store.
  463.                JMP     SHORT DO_PARAMETER      ;Else, check other codes.
  464.  
  465. ;------------------------------------------------;
  466.  
  467. CLS_STATE:     CMP     AL,"J"                  ;Is it second character of CLS?
  468.                MOV     DI,OFFSET COMMAND_END   ;If yes, execute
  469.                JZ      EXECUTE                 ; Erase in Display procedure.
  470.                TEST    STATUS,OFF              ;ANSI OFF?  If yes, flush buffer.
  471.                JNZ     FLUSH_BUFFER            ; If not fall through to process.
  472.                MOV     BYTE PTR NUMBER_BUFFER,2   ;Store the previous 2.
  473. DO_PARAMETER:  MOV     ANSI_STATE,OFFSET PARAM_STATE  ;Parameter state.
  474.  
  475. ;------------------------------------------------;
  476.  
  477. PARAM_STATE:   CALL    CK_QUOTE                ;Is it single or double quotes?
  478.                JZ      STORE_STATE             ;If yes, store string state.
  479.                CMP     AL,";"                  ;Is it semi-colon delimiter?
  480.                JNZ     CK_NUMBER               ;If no, check if number.
  481.                INC     NUMBER_COUNT            ;Else, increment number count.
  482.                JMP     SHORT BUFFER_CHAR       ;Buffer the semi-colon.
  483.  
  484. CK_NUMBER:     CMP     AL,"0"                  ;Is it below 0 ?
  485.                JB      FLUSH_BUFFER            ;If yes, illegal; flush buffer.
  486.                CMP     AL,"9"                  ;Else, is it above 9 ?
  487.                JA      DO_COMMAND              ;If yes, check for command char.
  488.                CALL    ACCUMULATE              ;Else it's a number; accumulate.
  489.                JMP     SHORT BUFFER_CHAR       ;Buffer the character.
  490.  
  491. DO_COMMAND:    MOV     DI,OFFSET COMMAND_TABLE ;Point to legal ANSI commands.
  492.                MOV     CX,COMMAND_LENGTH       ;Number of commands.
  493.                REPNZ   SCASB                   ;Check for a match.
  494.                JNZ     FLUSH_BUFFER            ;If no match, flush sequence.
  495.                INC     NUMBER_COUNT            ;Else, increment for last number.
  496.                MOV     DI,OFFSET COMMAND_END   ;Point to appropriate command
  497.                SHL     CX,1                    ; processing procedure.
  498.                SUB     DI,CX
  499. EXECUTE:       CALL    GET_BIOS_DATA           ;Get cursor position data.
  500.                CALL    DS:[DI]                 ;Do command subroutine.
  501.                JMP     SHORT FLUSH_END         ;Clear buffer.
  502.  
  503. ;------------------------------------------------;
  504.  
  505. QUOTE_STATE:   CMP     AL,QUOTE_TYPE           ;Is it an ending string quote?
  506.                JNZ     BUFFER_CHAR             ;If no, buffer literal.
  507.                MOV     BX,OFFSET PARAM_STATE   ;Else, back to parameter parsing.
  508.  
  509. ;------------------------------------------------;
  510.  
  511. STORE_STATE:   MOV     ANSI_STATE,BX           ;Store the ANSI state.
  512.  
  513. ;------------------------------------------------;
  514.  
  515. BUFFER_CHAR:   MOV     DI,ESC_COUNT            ;Buffer the character in case
  516.                CMP     DI,ESC_BUFFER_SIZE      ; ending ANSI command is illegal.
  517.                JZ      FLUSH_BUFFER            ;If buffer full, flush.
  518.                ADD     DI,OFFSET ESC_BUFFER    ;Point to next buffer position.
  519.                STOSB                           ;Store the character.
  520.                INC     ESC_COUNT               ;Increment the sequence count.
  521.                RET
  522.  
  523. ;------------------------------------------------;
  524.  
  525. FLUSH_BUFFER:  CALL    BUFFER_CHAR             ;@ Buffer current character also!
  526. ;@               PUSH    AX                      ;Save the current character.
  527. FLUSH_BUFF2:   MOV     SI,OFFSET ESC_BUFFER    ;@ Point to the sequence buffer.
  528.                MOV     CX,ESC_COUNT            ;Count of buffered characters.
  529. NEXT_FLUSH:    LODSB                           ;Retrieve one.
  530.                PUSH    CX                      ;Save counter and pointer.
  531.                PUSH    SI
  532.                CALL    WRITE_CHAR              ;Write character to screen.
  533.                POP     SI                      ;Restore counter and pointer.
  534.                POP     CX
  535.                LOOP    NEXT_FLUSH              ;Flush entire buffer.
  536. ;@               POP     AX                      ;Retrieve last character.
  537. ;@               CALL    WRITE_CHAR              ;Write it also.
  538. FLUSH_END:     MOV     ESC_COUNT,0                   ;Reset counter.
  539.                MOV     ANSI_STATE,OFFSET ESC_STATE   ;Back to Esc state.
  540.                MOV     NUMBER_COUNT,0                ;Reset parameter counter.
  541.                PUSH    CS                            ;Point to our data.
  542.                POP     ES
  543.                MOV     DI,OFFSET NUMBER_BUFFER       ;Clear number buffer
  544.                MOV     CX,ESC_BUFFER_SIZE / 2        ; to zeros.
  545.                XOR     AX,AX
  546.                REP     STOSW
  547.                RET
  548.  
  549. ;------------------------------------------------;@
  550. COLOR_STATE:   CMP     AL,"0"                  ;@ Is it below 0 ?
  551.                JB      FLUSH_BUFFER            ;@ If yes, illegal; flush buffer.
  552.                CMP     AL,"9"                  ;@ Else, is it 0 - 9 ?
  553.                JBE     DO_COLOR                ;@ If yes, Make color.
  554.                CMP     AL,'A'                  ;@ Is it below A ?
  555.                JB      FLUSH_BUFFER            ;@ If yes, illegal; flush buffer.
  556.                CMP     AL,'F'                  ;@ Is it Above F ?
  557.                JA      FLUSH_BUFFER            ;@ If yes, illegal; flush buffer.
  558.                SUB     AL,7                    ;@ Else, adjust for Hex
  559. DO_COLOR:      CALL    ACCUM_COLOR             ;@ Accumulate Color.
  560.                INC     NUMBER_COUNT            ;@ Count the character
  561.                CMP     NUMBER_COUNT,2          ;@ Already got two?
  562. BUFFER_JUMP:   JNE     SHORT BUFFER_CHAR     ;&;@ No, Buffer the character.
  563.                TEST    STATUS,OFF              ;@ Else, is ANSI OFF ?
  564.                JNZ     FLUSH_BUFFER            ;@ If yes, flush Esc, bracket.
  565.                INC     CL                      ;& Is it @XFF restore code?
  566.                JNZ     COLOR_2                 ;& No,  Check for save code
  567.                MOV     CL,SAVE_ATTRIBUTE       ;& Yes, Get back saved attribute
  568.                JMP     SHORT COLOR_3           ;& and set it
  569. COLOR_2:       DEC     CL                      ;& Is it @X00 save code
  570.                JNZ     COLOR_3                 ;& No,  just set it then
  571.                MOV     CL,ATTRIBUTE            ;& Yes, Save the attribute
  572.                MOV     SAVE_ATTRIBUTE,CL       ;&
  573.                JMP     FLUSH_END               ;& and flush it
  574. COLOR_3:       MOV     ATTRIBUTE,CL            ;@ Set Attribute
  575.                JMP     FLUSH_END               ;@ Clear Buffer
  576.  
  577. ;------------------------------------------------;@
  578. VARIABLE_SUB:  CMP     AL,'@'                  ;@ Is it another @
  579.                JB      SHORT_FLUSH             ;@ No, and not valid, so flush
  580.                JNZ     BUFFER_JUMP           ;&;@ No, Buffer the Char (indirect)
  581.                MOV     DX,OFFSET AT_VARIABLE_TABLE ;@ Point to Variable List
  582.                XOR     BX,BX                   ;@ Position in Variable List
  583. NEXT_VARI:     MOV     DI,DX                   ;@ Load DI
  584.                INC     BX                      ;@ Count the Variable
  585.                MOV     SI,OFFSET ESC_BUFFER    ;@ Point to our Variable
  586.                MOV     CX,OFFSET LAST_VARIABLE ;@ Point to End of list
  587.                SUB     CX,DI                   ;@ Minus our current location
  588.                MOV     AL,'@'                  ;@ We need to start on these
  589.                REPNE   SCASB                   ;@ so find one
  590.                JCXZ    SHORT_FLUSH             ;@ End of List? Yes
  591.                MOV     DX,DI                   ;@ No,Save Variable list pointer
  592.                DEC     DI                      ;@ No, Back up to the @
  593.                MOV     CX,ESC_COUNT            ;@ Length of Variable
  594.                REP     CMPSB                   ;@ See if this one matches?
  595.                JNZ     NEXT_VARI               ;@ Didn't match that one!
  596.                CMP     [DI],AL                 ;@ Last Character has to be an @
  597.                JNZ     NEXT_VARI               ;@ Nope
  598.                DEC     BX                      ;@ Back up 1
  599.                CMP     BX,11                   ;@ Is it an Action code
  600.                JA      NOT_ACTION              ;@ No
  601.                SHL     BX,1                    ;@ BX x 2 for proper offset
  602.                MOV     DI,OFFSET JUMP_TABLE    ;@ Point to command table
  603.                ADD     DI,BX                   ;@ Adjust to the desired command
  604.                JMP     EXECUTE                 ;@ Execute the command
  605. NOT_ACTION:    MOV     SI, OFFSET SUB_TABLE    ;@ Point to Sub Table
  606.                MOV     AX,BX                   ;@ Save Variable Number
  607.                MOV     CX,BX                   ;@ Copy Variable Number
  608.                XOR     BX,BX                   ;@ Zero Offset
  609.                XOR     DX,DX                   ;@ Zero out initial length
  610.                SUB     CX,11                   ;@ Adjust Variable Number
  611. NEXT_OFFSET:   ADD     BX,DX                   ;@ Add last Length to Offset
  612.                MOV     DL,[SI]                 ;@ Get Length
  613.                INC     SI                      ;@ Bump the pointer
  614.                LOOP    NEXT_OFFSET             ;@ Do all of them
  615.                MOV     CX,DX                   ;@ Get last Length
  616.                MOV     SI,OFFSET SUB_LIST      ;@ Point to the substitue buffer.
  617.                ADD     SI,BX                   ;@ Add Offset
  618.                SUB     AX,34                   ;@ Is It a String Variable
  619.                JB      IS_STRING               ;@ Yes, Flush our Substitute
  620.                CMP     AX,1                    ;@ Is it Date ot Time?
  621.                JBE     IS_TIMEDATE             ;@ No, It's a Number
  622.                SUB     AX,2                    ;@ Adjust Variable number
  623.                CALL    NUMBER_PARSE            ;@ Create a Numeric value then
  624.                JMP     SHORT VAR_END           ;@ Flush our Number
  625. IS_TIMEDATE:   CALL    MAKE_TIMEDATE           ;@
  626. IS_STRING:     MOV     DI,SI                   ;@ Copy Pointer to DI for SCASB
  627.                MOV     AL,0                    ;@ We look for a Zero
  628.                REPNE   SCASB                   ;@ Findit it
  629.                JNE     GOT_END                 ;@ Skip if we didn't hit a Zero
  630.                DEC     DI                      ;@ Back up if we did
  631. GOT_END:       MOV     CX,DI                   ;@ Get Current Location
  632.                SUB     CX,SI                   ;@ Subtract Starting Location
  633. VAR_END:       JMP     NEXT_FLUSH              ;@ Flush our Substitute
  634.  
  635. SHORT_FLUSH:   PUSH    AX                      ;& Save Character
  636.                CALL    FLUSH_BUFF2             ;@ Flush what we have now
  637.                POP     AX                      ;& Restore Character
  638.                JMP     ESC_STATE               ;& And save the new state
  639.  
  640. ;------------------------------------------------;@
  641. ATX_STATE:     MOV     BX,OFFSET COLOR_STATE   ;@ Assume 'X' Character
  642.                CMP     AL,"X"                  ;@ Is it X? If yes, store
  643.                JZ      SHORT_STORE             ;@ char. and next state.
  644.                CMP     AL,'@'                  ;@ Is it another '@' already?
  645.                JZ      WRITE_CHAR              ;@ Yes!
  646.                CMP     AL,ESC_CHAR             ;& Is it an Escape
  647.                JE      SHORT_FLUSH             ;& Yes, so flush buffer & restart
  648.                MOV     BX,OFFSET VARIABLE_SUB  ;@ No, Must be a Variable
  649. SHORT_STORE:   JMP     STORE_STATE             ;@ Store the state
  650.  
  651. ;------------------------------------------------;
  652. ; Slow video writes are via BIOS Write TTY.      ;
  653. ;------------------------------------------------;
  654.  
  655. WRITE_CHAR:    CMP     AL,BELL                 ;Let BIOS process BS and BELL.
  656.                JZ      WRITE_TTY
  657.                CMP     AL,BS
  658.                JZ      WRITE_TTY
  659.  
  660.                CALL    GET_BIOS_DATA           ;Get BIOS video data.
  661.                CMP     AL,TAB                  ;Is character a TAB?
  662.                JNZ     CK_ACTIVE               ;If no, process normally.
  663.                MOV     CX,CURSOR_POSN          ;Else, expand TAB to
  664.                AND     CX,7                    ; appropriate space characters.
  665.                NEG     CX
  666.                ADD     CX,8
  667. NEXT_TAB:      PUSH    CX
  668.                MOV     AL,SPACE
  669.                CALL    CK_ACTIVE
  670.                POP     CX
  671.                LOOP    NEXT_TAB
  672.                RET
  673.  
  674. CK_ACTIVE:     TEST    STATUS,OFF              ;Is ANSI OFF?
  675.                JNZ     WRITE_TTY               ;If yes, write via BIOS TTY.
  676. CK_FAST:       CALL    CK_SLOW_TEXT            ;Is ANSI SLOW or in graphics
  677.                JNC     WRITE_FAST              ; mode? If no, write fast.
  678.  
  679.                CMP     AL,CR                   ;Let BIOS handle CR and LF.
  680.                JZ      WRITE_TTY
  681.                CMP     AL,LF
  682.                JZ      WRITE_TTY
  683.  
  684. WRITE_SLOW:    PUSH    AX                      ;Else, write character/attribute
  685.                MOV     CX,1                    ; at current cursor position
  686.                MOV     BH,ACTIVE_PAGE          ; via BIOS.
  687.                MOV     BL,ATTRIBUTE
  688.                MOV     AH,9
  689.                INT     10H
  690.                POP     AX
  691.  
  692.                CMP     LINE_WRAP,ON            ;Is line wrap on?
  693.                JZ      TTY                     ;If yes, continue.
  694.                MOV     CX,CRT_COLS             ;Else, cursor at rightmost
  695.                DEC     CL                      ; column?
  696.                CMP     CL,CURSOR_COL           ;If yes, continue, else
  697.                JNZ     TTY                     ; return without writing.
  698.                RET
  699.  
  700. ;------------------------------------------------;
  701.  
  702. WRITE_TTY:     MOV     BL,7                    ;Attribute in graphics mode.
  703. TTY:           MOV     AH,0EH
  704.                INT     10H
  705.                RET
  706.  
  707. ;----------------------------------------------------------------------------;
  708. ; Fast screen writes are directly to the video buffer without retrace check. ;
  709. ;----------------------------------------------------------------------------;
  710.  
  711. WRITE_FAST:    PUSH    ES                      ;Preserve extra segment.
  712.                MOV     DX,CURSOR_POSN          ;Retrieve cursor position.
  713.                CMP     AL,CR                   ;Carriage return?
  714.                JNZ     CK_LINEFEED             ;If no, check linefeed.
  715.                XOR     DL,DL                   ;Else, cursor to first column.
  716.                JMP     SHORT UPDATE_CURSOR
  717. CK_LINEFEED:   CALL    VIDEO_SETUP             ;Calculate video address.
  718.                CMP     AL,LF                   ;Linefeed?
  719.                JZ      NEXT_ROW                ;If yes, next row.
  720.  
  721.                MOV     AH,ATTRIBUTE            ;Retrieve attribute.
  722.                STOSW                           ;Put char/attrib in video buffer.
  723.                INC     DL                      ;Increment cursor column.
  724.                CMP     DL,BYTE PTR CRT_COLS    ;End of row?
  725.                JB      UPDATE_CURSOR           ;If no, update cursor.
  726.  
  727.                CMP     LINE_WRAP,OFF           ;Else, line wrap off?
  728.                JZ      FAST_END                ;If yes, don't move cursor.
  729.                XOR     DL,DL                   ;Else, column zero.
  730. NEXT_ROW:      INC     DH                      ;Next row.
  731.                CALL    INFORMATION             ;Get displayable row info.
  732.                CMP     DH,AL                   ;Beyond the bottom of screen?
  733.                JBE     UPDATE_CURSOR           ;If no, update cursor.
  734.  
  735.                DEC     DH                      ;Else, cursor to original row.
  736.                MOV     AX,CRT_COLS             ;. Get number of columns
  737.                PUSH    DX                      ;. Save Cursor position
  738.                PUSH    AX                      ;. Save Columns
  739.                SHL     AX,1                    ;. Twice for Char/Attribute
  740.                MOV     SI,AX                   ;. Starting offset in SI
  741.                MOV     DL,START_SCROLL         ;. Where we allow scroll to start
  742.                MUL     DL                      ;. Calculate offset in AX
  743.                SUB     DH,DL                   ;. Reduce line count
  744.                MOV     DI,CRT_START            ;Point destination to top.
  745.                ADD     DI,AX                   ;. Add offset
  746.                ADD     SI,DI                   ;. Point source to second row
  747.                POP     AX                      ;. Get Back Columns
  748.                PUSH    AX                      ;. Save it again
  749.                MUL     DH                      ;Times displayable rows - 1.
  750.                MOV     CX,AX                   ; equals char/attrib to scroll.
  751.                PUSH    DS                      ;Save data segment and
  752.                PUSH    ES                      ; point to video segment.
  753.                POP     DS
  754.                REP     MOVSW                   ;Scroll the screen.
  755.                POP     DS                      ;Restore data segment.
  756.                POP     CX                      ;Retrieve CRT columns.
  757.                POP     DX                      ;.Get back Cursor info
  758.                MOV     AL,SPACE                ;Write space/attrib to
  759.                MOV     AH,ATTRIBUTE            ; bottom row.
  760.                REP     STOSW
  761.  
  762. UPDATE_CURSOR: CALL    SET_CURSOR              ;Update the cursor position.
  763. FAST_END:      POP     ES                      ;Restore extra segment.
  764.                RET
  765.  
  766. ;@************ SUPPORT ROUTINES *************;
  767.  
  768. QOFF:          MOV     AL,0FFH                 ;& Show QOFF
  769.                JMP     SHORT QON2              ;&
  770. QON:           XOR     AL,AL                   ;& Show QON
  771. QON2:          MOV     Q_STATE,AL              ;& Store the state
  772.                RET                             ;& All done
  773.  
  774. BEEP:          MOV     AL,7                    ;@
  775.                JMP     WRITE_CHAR              ;@
  776. MORE:          MOV     AX,MORE_DELAY           ;@
  777.                JMP     SHORT PAUSE2            ;@
  778. PAUSE:         MOV     AX,PAUSE_DELAY          ;@
  779. PAUSE2:        CMP     Q_STATE,0               ;& Are we at a QOFF state
  780.                JNZ     WAIT1                   ;& Yes, then these are WAITs
  781.                MOV     SI,OFFSET MORE_PROMPT   ;@ Point to More? Prompt
  782.                MOV     CX,MORE_LENGTH          ;@ Get the Length of it
  783.                JMP     SHORT WAIT2             ;@ Go Wait
  784. WAIT1:         MOV     AX,WAIT_DELAY           ;@
  785.                MOV     SI,OFFSET WAIT_PROMPT   ;@ Point to Wait Prompt
  786.                MOV     CX,WAIT_LENGTH          ;@ Get the Length of it
  787. WAIT2:         MOV     PAUSE_TIMER,AX          ;@
  788. ;               PUSH    CX                      ;@ Save Length
  789. WAIT2_LOOP:    LODSB                           ;@ Get Character
  790.                PUSH    CX                      ;@
  791.                PUSH    SI                      ;@
  792.                CALL    WRITE_CHAR              ;@ Output it
  793.                POP     SI                      ;@
  794.                POP     CX                      ;@
  795.                LOOP    WAIT2_LOOP              ;@ Do all the Characters
  796. WAIT_LOOP:     MOV     AH,1                    ;@ KeyBoard Status
  797.                INT     16H                     ;@ Keyboard I/O Services
  798.                JNZ     CONTINUE                ;@ Key Hit!
  799.                CMP     PAUSE_TIMER,0           ;@ Timer Run out?
  800.                JNE     WAIT_LOOP               ;@ No
  801.                JMP     SHORT WAIT3             ;@ Yes
  802. CONTINUE:      MOV     AH,0                    ;@ KeyBoard Read
  803.                INT     16H                     ;@ Keyboard I/O Services
  804. WAIT3:                                         ;@
  805.                XOR     CL,CL                   ;@ Clear the Attribute
  806.                XCHG    CL,ATTRIBUTE            ;&  and
  807.                PUSH    CX                      ;&    save it too
  808.                MOV     DX,CURSOR_POSN          ;& Get Cursor
  809.                MOV     DL,0                    ;& First column
  810.                CALL    SET_CURSOR              ;& Set the new Cursor
  811.                CALL    ERASE_2                 ;& Erase the line
  812. ;&
  813. ;& The following lines (and the PUSH CX above) will clear only the PROMPT
  814. ;& and leave the cursor where it was when the prompt appears. This was
  815. ;& different than PCBoard 14.5 so I changed it to clear the entire line
  816. ;& via the above four lines. Left the old code in case someome wanted it.
  817. ;&
  818. ;&               POP     CX                      ;@ Get back Length
  819. ;&ERASE_LOOP:    PUSH    CX                      ;@ Save it again
  820. ;&               MOV     AL,BS                   ;@ Send BS
  821. ;&               CALL    WRITE_CHAR              ;@  character
  822. ;&               MOV     AL,' '                  ;@  and then space
  823. ;&               CALL    WRITE_CHAR              ;@  character to erase
  824. ;&               MOV     AL,BS                   ;@  then BS again
  825. ;&               CALL    WRITE_CHAR              ;@  to backup.
  826. ;&               POP     CX                      ;@ get back length again
  827. ;&               LOOP    ERASE_LOOP              ;@ Erase entire prompt.
  828.                POP     CX                      ;& Restore
  829.                MOV     ATTRIBUTE,CL            ;&  the Attribute
  830.                RET                             ;@
  831. AUTOOFF:       MOV     AX,WAIT_DELAY           ;@ Restore More to a Wait
  832.                JMP     SHORT AUTO2             ;@
  833. AUTOMORE:      MOV     AX,PAUSE_DELAY          ;@ Make More a Pause
  834. AUTO2:         MOV     MORE_DELAY,AX           ;@
  835. SKIP_IT:       RET                             ;@
  836.  
  837. ;************* SUPPORT ROUTINES *************;
  838.  
  839. CK_QUOTE:      MOV     BX,OFFSET QUOTE_STATE   ;Assume quote state.
  840.                MOV     AH,DOUBLE_QUOTE
  841.                CMP     AL,AH                   ;Is it double quote?
  842.                JZ      GOT_QUOTE               ;If yes, string delimiter.
  843.                MOV     AH,SINGLE_QUOTE         ;Is it single quote?
  844.                CMP     AL,AH                   ;Is yes, string delimiter.
  845.                JNZ     QUOTE_END               ;Else, return ZR = 0.
  846. GOT_QUOTE:     MOV     QUOTE_TYPE,AH           ;Store as matching string end.
  847. QUOTE_END:     RET
  848.  
  849. ;------------------------------------------------;
  850.  
  851. ACCUMULATE:    PUSH    AX                      ;Preserve number character.
  852.                SUB     AL,"0"                  ;Convert ASCII to binary.
  853.                MOV     CL,AL                   ;Save the number.
  854.                MOV     AX,10                   ;Multiply previous count by 10.
  855.                MOV     BX,NUMBER_COUNT
  856.                MUL     BYTE PTR NUMBER_BUFFER[BX]
  857.                ADD     AL,CL                            ;Add in new number
  858.                MOV     BYTE PTR NUMBER_BUFFER[BX],AL    ; and store.
  859.                POP     AX
  860.                RET
  861.  
  862. ;------------------------------------------------;@
  863.  
  864. ACCUM_COLOR:   PUSH    AX                      ;@ Preserve number character.
  865.                SUB     AL,"0"                  ;@ Convert ASCII to hex
  866.                MOV     AH,BYTE PTR NUMBER_BUFFER ;@ Get current number
  867.                SHL     AH,1                      ;@ Shift left 4 bits
  868.                SHL     AH,1                      ;@
  869.                SHL     AH,1                      ;@
  870.                SHL     AH,1                      ;@
  871.                OR      AH,AL                     ;@ Add in new number
  872.                MOV     BYTE PTR NUMBER_BUFFER,AH ;@ and store.
  873.                MOV     CL,AH                     ;@ Return with Color in CL
  874.                POP     AX                        ;@
  875.                RET                               ;@
  876.  
  877. NUMBER_PARSE:  MOV  BX,[SI]                 ;@ Get low word
  878.                MOV  DX,AX                   ;@ Save Variable Number
  879.                XOR  AX,AX                   ;@ Assume Integer
  880.                CMP  CX,4                    ;@ Is that a Long Integer?
  881.                JNE  SHORT_INT               ;@ No, Integer
  882.                MOV  AX,[SI + 2]             ;@ Yes, Get high word
  883. SHORT_INT:     MOV  DI, OFFSET PARSE_BUFFER ;@ Point DI at number space
  884.                MOV  CX,10                   ;@ Set divisor to 10
  885.                XOR  SI,SI                   ;@ Clear SI as counter
  886.                MOV  COMMA,2                 ;@ Assume a Ratio
  887.                CMP  DX,2                    ;@ Is it a Ratio?
  888.                JB   GETDIGIT                ;@ No
  889. RESET_COMMA:   MOV  COMMA,4                 ;@ Set Comma Counter
  890. GETDIGIT:      DEC  DI                      ;@ Point DI at correct character
  891.                INC  SI                      ;@ Register that we have a character
  892.                DEC  COMMA                   ;@ Do we need a Comma?
  893.                JNZ  NO_COMMA                ;@ No
  894.                MOV  BYTE PTR [DI],','       ;@ Yes, So Put one in!
  895.                JMP  RESET_COMMA             ;@ And restart the Comma count.
  896. NO_COMMA:      XOR  DX,DX                   ;@ Clear DX to take remainder
  897.                DIV  CX                      ;@ Divide AX first (High word)
  898.                MOV  BP,AX                   ;@ Save quotient
  899.                MOV  AX,BX                   ;@ Get low word
  900.                DIV  CX                      ;@ DX had leftover from first divide
  901.                MOV  BX,AX                   ;@ Save quotient
  902.                MOV  AX,BP                   ;@ Put high word back
  903.                ADD  DL,30h                  ;@ Make it an ASCII digit from remainder
  904.                MOV  [DI],DL                 ;@ Put it in our string
  905.                OR   AX,AX                   ;@ Is high word zero?
  906.                JNZ  GETDIGIT                ;@ No keep going
  907.                OR   BX,BX                   ;@ Is low word zero?
  908.                JNZ  GETDIGIT                ;@ No keep going
  909.                MOV  CX,SI                   ;@ Digit count to CX
  910.                MOV  SI,DI                   ;@ String Pointer to SI
  911.                MOV  DI, OFFSET PARSE_BUFFER ;@ Point DI at number space
  912.                CMP  BYTE PTR [DI][-2],','   ;@ Was it a Ratio
  913.                JNE  NOT_RATIO               ;@ No, nevermind
  914.                MOV  BYTE PTR [DI][-2],'.'   ;@ Change comma to Decimal
  915.                MOV  BYTE PTR [DI],":"       ;@ Yes, Add ':1' to it
  916.                MOV  BYTE PTR [DI][1],"1"    ;@
  917.                ADD  CX,2                    ;@ Account for two more characers
  918. NOT_RATIO:     RET                          ;@
  919.  
  920. MAKE_TIMEDATE: MOV  DI, OFFSET NUMBER_BUFFER ;@ Point to Number Buffer
  921.                MOV  SI,DI            ;@ Save it in SI too
  922.                JE   MAKE_TIME        ;@ It was TIME on Entry!
  923.                MOV  CX,8             ;@ It was DATE! Length = 8
  924.                PUSH CX               ;@ Save Length
  925.                MOV  AH,04H           ;@ Get date service
  926.                INT  1AH              ;@ Call BIOS - return codes as follows:
  927.                PUSH CX               ;@ CH = Century (19-20)  CL = Year (00-99)
  928.                PUSH DX               ;@ DH = Month   (1-12)   DL = Day  (00-31)
  929.                MOV  AL,DH            ;@ Month
  930.                CALL ASCII            ;@ Convert byte to ASCII digits
  931.                MOV  AL,'-'           ;@
  932.                STOSB                 ;@
  933.                POP  AX               ;@ Day - was DX when pushed
  934.                CALL ASCII            ;@ Convert byte to ASCII digits
  935.                MOV  AL,'-'           ;@
  936.                STOSB                 ;@
  937.                POP  AX               ;@ Year - was CX when pushed
  938.                POP  CX               ;@ Restore Length
  939.                JMP  SHORT ASCII      ;@ Convert byte to ASCII digit
  940.  
  941. MAKE_TIME:     MOV  CX,5             ;@ Length = 5
  942.                PUSH CX               ;@ Save Length
  943.                MOV  AH,02H           ;@ Get time service
  944.                INT  1AH              ;@ Call BIOS - return codes as follows:
  945.                PUSH CX               ;@ CH = Hours   (0-23)   CL = Minutes (0-59)
  946.                MOV  AL,CH            ;@ Hours
  947.                CALL ASCII            ;@ Convert byte to ASCII digits
  948.                MOV  AL,':'           ;@
  949.                STOSB                 ;@
  950.                POP  AX               ;@ Minutes - was CX when pushed
  951.                POP  CX               ;@ Restore Length
  952. ASCII:         MOV  AH,AL            ;@ Need to get BCD Digits
  953.                SHR  AL,1             ;@  MSD in AL
  954.                SHR  AL,1             ;@   lower
  955.                SHR  AL,1             ;@     4
  956.                SHR  AL,1             ;@     Bits
  957.                AND  AH,0FH           ;@ And LSD in AH cleanly
  958.                OR   AX,3030H         ;@ Convert to ASCII
  959.                STOSW                 ;@ Stuff Digits into Buffer (in reverse)
  960.                RET                   ;@ SI Points to String Data
  961.  
  962. ;---------------------------------------------------------------------------;
  963. ; OUTPUT:  CY = 1 if write SLOW mode or in graphics mode; CY = 0 otherwise. ;
  964. ;---------------------------------------------------------------------------;
  965.  
  966. CK_SLOW_TEXT:  TEST    STATUS,SLOW
  967.                JNZ     SLOW_MODE
  968.                CMP     CRT_MODE,7
  969.                JZ      TEXT_MODE
  970.                CMP     CRT_MODE,3
  971.                JA      SLOW_MODE
  972. TEXT_MODE:     CLC
  973.                RET
  974.  
  975. SLOW_MODE:     STC
  976.                RET
  977.  
  978. ;-------------------------------------;
  979. ; OUTPUT:  AL = Screen rows minus one ;
  980. ;-------------------------------------;
  981.  
  982. INFORMATION:   PUSH    DS                      ;Save data segment.
  983.                MOV     AX,40H                  ;Point to BIOS data.
  984.                MOV     DS,AX
  985.                MOV     AL,DS:[84H]             ;Retrieve rows - 1.
  986.                OR      AL,AL                   ;BIOS supported?
  987.                JNZ     INFO_END                ;If yes, done here.
  988.                MOV     AL,24                   ;Else, assume 25 lines.
  989. INFO_END:      POP     DS
  990.                RET
  991.  
  992. ;------------------------------------------------------------------------------;
  993. ; INPUT:  DX = Cursor position.                                                ;
  994. ; OUTPUT: ES = Video buffer segment; DI = Video buffer offset; AX,DX preserved ;
  995. ;------------------------------------------------------------------------------;
  996.  
  997. VIDEO_SETUP:   PUSH    AX
  998.                MOV     AX,CRT_COLS             ;Retrieve CRT columns.
  999.                MUL     DH                      ;Times cursor row.
  1000.                MOV     BL,DL
  1001.                XOR     BH,BH
  1002.                ADD     AX,BX                   ;Plus cursor column.
  1003.                SHL     AX,1                    ;Times two for attribute.
  1004.                MOV     DI,CRT_START            ;Plus starting video offset.
  1005.                ADD     DI,AX                   ;Equals destination.
  1006.  
  1007.                MOV     BX,0B000H               ;Assume mono card.
  1008.                CMP     ADDR_6845,3B4H          ;Is it mono port?
  1009.                JZ      VIDEO_SEGMENT           ;If yes, guessed right.
  1010.                ADD     BX,800H                 ;Else, point to color segment.
  1011. VIDEO_SEGMENT: MOV     ES,BX
  1012.                POP     AX
  1013.                RET
  1014.  
  1015. ;------------------------------------------------;
  1016. ; Move BIOS video data into our data segment.    ;
  1017. ;------------------------------------------------;
  1018.  
  1019. GET_BIOS_DATA: PUSH    DS
  1020.                PUSH    DI                      ;Point to BIOS data segment.
  1021.                MOV     BX,40H
  1022.                MOV     DS,BX
  1023.                MOV     SI,BIOS_ACTIVE_PAGE     ;Start with active page.
  1024.                MOV     DI,OFFSET ACTIVE_PAGE
  1025.                MOVSB                           ;Retrieve active page
  1026.                MOVSW                           ; and address of 6845 port.
  1027.                MOV     SI,BIOS_CRT_MODE        ;Retrieve CRT mode, CRT columns,
  1028.                MOV     CX,CRT_DATA_LENGTH      ; CRT length, CRT start.
  1029.                REP     MOVSB
  1030.                MOV     BL,ES:ACTIVE_PAGE       ;Use active page as index
  1031.                XOR     BH,BH                   ; of active cursor position.
  1032.                SHL     BX,1
  1033.                ADD     SI,BX
  1034.                MOVSW
  1035.                POP     DI
  1036.                POP     DS
  1037.                RET
  1038.  
  1039. ;----------------------------------------------------------------------------;
  1040. ; OUTPUT: BL = First parameter; BH = Second parameter; DX = cursor position. ;
  1041. ;----------------------------------------------------------------------------;
  1042.  
  1043. ADJUST_NUMBER: MOV     BX,WORD PTR NUMBER_BUFFER
  1044.                OR      BH,BH
  1045.                JNZ     ADJUST_AL               ;If either parameter zero,
  1046.                INC     BH                      ; increment to convert
  1047. ADJUST_AL:     OR      BL,BL                   ; to base one.
  1048.                JNZ     ADJUST_END
  1049.                INC     BL
  1050. ADJUST_END:    MOV     DX,CURSOR_POSN          ;Return cursor position.
  1051.                RET
  1052.  
  1053. ;--------------------------------------------------------------------------;
  1054. ; INPUT:  AX = number; BP = 0 if console output; BP = 1 if storage output. ;
  1055. ;--------------------------------------------------------------------------;
  1056.  
  1057. DECIMAL_OUT:   MOV     BX,10                   ;Divisor of ten.
  1058.                XOR     CX,CX                   ;Zero in counter.
  1059. NEXT_COUNT:    XOR     DX,DX                   ;Zero in high half.
  1060.                DIV     BX                      ;Divide by ten.
  1061.                ADD     DL,"0"                  ;Convert to ASCII.
  1062.                PUSH    DX                      ;Save results.
  1063.                INC     CX                      ;Also increment count.
  1064.                CMP     AX,0                    ;Are we done?
  1065.                JNZ     NEXT_COUNT              ;Continue until zero.
  1066.                OR      BP,BP                   ;If BP zero, output to screen.
  1067.                JNZ     DEVICE_OUTPUT           ;Else, store in buffer.
  1068.  
  1069. REPORT_OUTPUT: POP     AX                      ;Retrieve number.
  1070.                CALL    PRINT_CHAR              ;Display it.
  1071.                LOOP    REPORT_OUTPUT
  1072.                RET
  1073.  
  1074. DEVICE_OUTPUT: CMP     CX,2                    ;Two digits?
  1075.                JZ      TWO_DIGITS              ;If yes, process normally.
  1076.                MOV     AL,"0"                  ;Else, store leading zero.
  1077.                STOSB
  1078.  
  1079. TWO_DIGITS:    POP     AX                      ;Retrieve number.
  1080.                STOSB                           ;Store it
  1081.                LOOP    TWO_DIGITS
  1082.                RET
  1083.  
  1084. ;************* ANSI COMMAND SUBSET *************;
  1085.  
  1086. CLS:           MOV     BH,7                    ;Assume normal attribute.
  1087.                MOV     BL,BYTE PTR CRT_MODE    ;Get current video mode.
  1088.                CMP     BL,4
  1089.                JBE     CK_CLS_STATUS           ;If text mode then check if
  1090.                CMP     BL,7                    ; ANSI active.
  1091.                JZ      CK_CLS_STATUS
  1092.                XOR     BH,BH                   ;Else, use black attribute
  1093.                TEST    STATUS,OFF
  1094.                JNZ     CLS_SLOW                ;If ANSI inactive, via BIOS.
  1095.                JMP     SHORT CK_CLS_SLOW       ;Else, check if FAST or SLOW.
  1096.  
  1097. CK_CLS_STATUS: TEST    STATUS,OFF              ;Is ANSI OFF?
  1098.                JNZ     CLS_SLOW                ;If yes, CLS via BIOS.
  1099.                MOV     BH,ATTRIBUTE            ;Else, current attribute.
  1100. CK_CLS_SLOW:   CALL    CK_SLOW_TEXT
  1101.                JC      CLS_SLOW                ;If ANSI SLOW, via BIOS.
  1102.  
  1103. CLS_FAST:      MOV     AH,BH                   ;Else, attribute in high half.
  1104.                MOV     AL,SPACE                ;Space character in low half.
  1105.                XOR     DX,DX                   ;Cursor position home.
  1106.                CALL    VIDEO_SETUP             ;Calculate video address.
  1107.                MOV     CX,CRT_LEN              ;Retrieve CRT length.
  1108.                SHR     CX,1                    ;Times two for attribute.
  1109.                REP     STOSW                   ;Write directly to video buffer.
  1110.                JMP     SHORT SET_CURSOR        ;Set the cursor top left corner.
  1111.  
  1112. CLS_SLOW:      CALL    INFORMATION             ;Get displayable rows.
  1113.                MOV     DH,AL                   ;Store in DH.
  1114.                MOV     DL,BYTE PTR CRT_COLS    ;Retrieve CRT columns.
  1115.                DEC     DL                      ;Adjust to zero base.
  1116.                XOR     CX,CX                   ;Scroll active page.
  1117.                MOV     AX,600H
  1118.                INT     10H
  1119.                XOR     DX,DX                   ;Home the cursor.
  1120.                JMP     SHORT SET_CURSOR
  1121.  
  1122. ;------------------------------------------------;
  1123. CURS_POSITION:                                 ;These two commands are the same.
  1124. HORZ_VERT_POS: CALL    INFORMATION             ;Returns AL = screen rows.
  1125.                CALL    ADJUST_NUMBER           ;Returns BL,BH = parameters.
  1126.                SUB     BX,101H                 ;Zero based.
  1127.                CMP     BL,AL                   ;If cursor request within
  1128.                JA      CURSOR_END              ; boundaries of screen, set it.
  1129.                CMP     BH,BYTE PTR CRT_COLS
  1130.                JAE     CURSOR_END
  1131.                XCHG    BH,BL
  1132.                MOV     DX,BX
  1133.  
  1134. SET_CURSOR:    MOV     BH,ACTIVE_PAGE          ;Set cursor via BIOS.
  1135.                MOV     AH,2
  1136.                INT     10H
  1137. CURSOR_END:    RET
  1138.  
  1139. ;------------------------------------------------;
  1140.  
  1141. CURSOR_UP:     CALL    ADJUST_NUMBER           ;Move cursor up one or more rows
  1142.                OR      DH,DH                   ; without changing column.
  1143.                JZ      CURSOR_END              ;If already at top, ignore.
  1144.                SUB     DH,BL
  1145.                JNC     SET_CURSOR              ;Stay in bounds.
  1146.                XOR     DH,DH
  1147.                JMP     SHORT SET_CURSOR
  1148.  
  1149. ;------------------------------------------------;
  1150.  
  1151. CURSOR_DOWN:   CALL    INFORMATION             ;Returns AL = screen rows.
  1152.                CALL    ADJUST_NUMBER           ;Returns BL,BH =nos.; DX = cursor
  1153.                CMP     DH,AL                   ;Move cursor down requested
  1154.                JZ      CURSOR_END              ; rows without changing column.
  1155.                ADD     DH,BL
  1156.                CMP     DH,AL
  1157.                JNA     SET_CURSOR
  1158.                MOV     DH,AL                   ;Stay in bounds.
  1159.                JMP     SHORT SET_CURSOR
  1160.  
  1161. ;------------------------------------------------;
  1162.  
  1163. CURS_FORWARD:  CALL    ADJUST_NUMBER           ;Returns BL,BH =nos.; DX = cursor
  1164.                MOV     BH,BYTE PTR CRT_COLS    ;Retrieve displayable columns.
  1165.                DEC     BH                      ;Adjust to zero base.
  1166.                CMP     DL,BH                   ;Move cursor forward one or more
  1167.                JZ      CURSOR_END              ; columns without changing row.
  1168.                ADD     DL,BL
  1169.                CMP     DL,BH
  1170.                JNA     SET_CURSOR
  1171.                MOV     DL,BH                   ;Stay in bounds.
  1172.                JMP     SHORT SET_CURSOR
  1173.  
  1174. ;------------------------------------------------;
  1175.  
  1176. CURS_BACKWARD: CALL    ADJUST_NUMBER           ;Returns BL,BH =nos.; DX = cursor
  1177.                OR      DL,DL                   ;Move cursor backward one or
  1178.                JZ      CURSOR_END              ; more columns without changing
  1179.                SUB     DL,BL                   ; row.  Ignore if already left.
  1180.                JNC     SET_CURSOR
  1181.                XOR     DL,DL                   ;Stay in bounds.
  1182.                JMP     SHORT SET_CURSOR
  1183.  
  1184. ;--------------------------------------------------------;
  1185. ; Report cursor position via console; Format: ESC[#;#R   ;
  1186. ;--------------------------------------------------------;
  1187.  
  1188. DEVICE_STATUS: MOV     DI,OFFSET DEVICE_STATUS_BUFFER
  1189.                MOV     AL,ESC_CHAR
  1190.                STOSB                           ;Store leading Esc, bracket
  1191.                MOV     AL,"["                  ;in special Device Status Buffer.
  1192.                STOSB
  1193.  
  1194.                MOV     AL,CURSOR_ROW           ;Retrieve cursor row.
  1195.                XOR     AH,AH                   ;Zero in high half.
  1196.                INC     AX                      ;Convert to base one.
  1197.                MOV     BP,1                    ;Flag as storage.
  1198.                CALL    DECIMAL_OUT             ;Convert to ASCII.
  1199.                MOV     AL,";"                  ;Store delimiting semi-colon.
  1200.                STOSB
  1201.                MOV     AL,CURSOR_COL           ;Do same with cursor column.
  1202.                XOR     AH,AH
  1203.                INC     AX
  1204.                CALL    DECIMAL_OUT
  1205.                MOV     AL,"R"                  ;Add command character
  1206.                STOSB
  1207.                MOV     AL,CR                   ; and carriage return.
  1208.                STOSB
  1209.                SUB     DI,OFFSET DEVICE_STATUS_BUFFER   ;Setup for console out.
  1210.                MOV     REASSIGN_COUNT,DI
  1211.                MOV     REASSIGN_POS,OFFSET DEVICE_STATUS_BUFFER
  1212.                MOV     REASSIGN_FLAG,ON
  1213.                MOV     REMOVE_FLAG,OFF
  1214.                RET
  1215.  
  1216. ;------------------------------------------------;
  1217.  
  1218. SAVE_CURSOR:   MOV     DX,CURSOR_POSN
  1219.                MOV     SAVE_POSITION,DX
  1220.                RET
  1221.  
  1222. ;------------------------------------------------;
  1223.  
  1224. RESTORE_CURS:  MOV     DX,SAVE_POSITION
  1225.                JMP     SET_CURSOR
  1226.  
  1227. ;------------------------------------------------;
  1228.  
  1229. ERASE_IN_LINE: MOV     DX,CURSOR_POSN          ;Erase from the cursor to
  1230. ERASE_2:       MOV     CX,CRT_COLS             ;& the end of the line, including
  1231.                SUB     CL,DL                   ; the current cursor position.
  1232.                CALL    CK_SLOW_TEXT
  1233.                JC      ERASE_SLOW              ;If ANSI ON and not graphics,
  1234.                CALL    VIDEO_SETUP             ; write directly to video buffer
  1235.                MOV     AL,SPACE                ; with space/attribute.
  1236.                MOV     AH,ATTRIBUTE
  1237.                REP     STOSW
  1238.                RET
  1239.  
  1240. ERASE_SLOW:    MOV     CX,DX                   ;Else, erase SLOW via
  1241.                MOV     DL,BYTE PTR CRT_COLS    ; BIOS scroll active page.
  1242.                DEC     DL
  1243.                MOV     BH,ATTRIBUTE
  1244.                MOV     AX,601H
  1245.                INT     10H
  1246.                RET
  1247.  
  1248. ;------------------------------------------------;
  1249. ;            Set Graphics Rendition              ;
  1250. ;------------------------------------------------;
  1251.  
  1252. SGR:           MOV     SI,OFFSET NUMBER_BUFFER     ;Point to number parameters.
  1253. NEXT_SGR:      LODSB                               ;Retrieve parameter.
  1254.                MOV     DI,OFFSET ATTRIBUTE_TABLE   ;Look up attribute in
  1255.                MOV     CX,ATTRIBUTE_LENGTH         ; translation table.
  1256.                REPNZ   SCASB
  1257.                JNZ     SGR_LOOP
  1258.  
  1259.                MOV     DI,OFFSET ATTRIBUTE_END
  1260.                SHL     CX,1
  1261.                SUB     DI,CX
  1262.                MOV     AX,[DI]
  1263.                AND     ATTRIBUTE,AL            ;If match, AND with strip mask.
  1264.                OR      ATTRIBUTE,AH            ;OR with add mask.
  1265. SGR_LOOP:      DEC     NUMBER_COUNT            ;Do all parameters.
  1266.                JNZ     NEXT_SGR
  1267.                RET
  1268.  
  1269. ;------------------------------------------------;
  1270.  
  1271. SET_MODE:      MOV     AH,ON                   ;Assume command 7,
  1272.                JMP     SHORT CK_WRAP           ; turn line wrap on.
  1273.  
  1274. ;------------------------------------------------;
  1275.  
  1276. RESET_MODE:    MOV     AH,OFF                     ;Assume turn line wrap off.
  1277. CK_WRAP:       MOV     AL,BYTE PTR NUMBER_BUFFER  ;Retrieve number parameter.
  1278.                CMP     AL,7                       ;Is it 7?
  1279.                JZ      SET_WRAP                ;If yes, set wrap mode.
  1280.                JB      DO_MODE                 ;1 - 6 valid modes.
  1281.                CMP     AL,14                   ;14 - 16 valid modes.
  1282.                JB      MODE_END
  1283.                CMP     AL,19
  1284.                JA      MODE_END                ;If above 16, illegal.
  1285. DO_MODE:       XOR     AH,AH                   ;Else, set video mode
  1286.                INT     10H                     ; to parameter.
  1287.                RET
  1288.  
  1289. SET_WRAP:      MOV     LINE_WRAP,AH
  1290. MODE_END:      RET
  1291.  
  1292. ;--------------------------------------------------------------------;
  1293. ; Keyboard Key Reassignment:  First convert ASCII numbers to binary, ;
  1294. ; parse out delimiting semi-colons, and quote string delimiters.     ;
  1295. ;--------------------------------------------------------------------;
  1296.  
  1297. REASSIGNMENT:  TEST    STATUS,POFF             ;:If assignment are OFF,
  1298.                JZ      NOT_POFF                ;:   then exit as if
  1299.                JMP     ASSIGN_FLUSH            ;:   we are out of room.
  1300. NOT_POFF:                                      ;:
  1301.                MOV     CX,ESC_COUNT            ;Retrieve length of Esc sequence.
  1302.                DEC     CX                          ;Adjust.
  1303.                MOV     SI,OFFSET ESC_BUFFER + 2    ;Point past Esc, bracket.
  1304.                MOV     DI,OFFSET PARSE_BUFFER      ;Point to parse storage.
  1305. NEXT_STRING:   MOV     QUOTE_TYPE,0                ;Reset quote type.
  1306. NEXT_NUM:      XOR     DL,DL                   ;Use DL to carry number; init = 0
  1307.                XOR     BP,BP                   ;Use BP as number flag.
  1308. NEXT_PARAM:    LODSB                           ;Retrieve a byte.
  1309.                DEC     CX                      ;Decrement string length counter.
  1310.                JZ      PARSE_END               ;If zero, done.
  1311.                MOV     AH,QUOTE_TYPE           ;Else, retrieve quote type.
  1312.                OR      AH,AH                   ;If zero, not in string.
  1313.                JNZ     QUOTE_MODE              ;Else, go to string mode.
  1314.                CALL    CK_QUOTE                ;Is character a quote?
  1315.                JZ      NEXT_PARAM              ;If yes, ignore.
  1316.                CMP     AL,";"                  ;Else, is it semi-colon?
  1317.                JZ      STORE_NUMBER            ;If yes, number delimiter.
  1318.  
  1319.                SUB     AL,"0"                  ;Else, must be number; convert
  1320.                MOV     DH,AL                   ; to binary; save in DH.
  1321.                MOV     AX,10                   ;Multiply current total by ten.
  1322.                MUL     DL
  1323.                ADD     AL,DH                   ;Add new number.
  1324.                MOV     DL,AL                   ;Save in DL.
  1325.                MOV     BP,1                    ;Flag that number mode active.
  1326.                JMP     SHORT NEXT_PARAM        ;Next parameter.
  1327.  
  1328. STORE_NUMBER:  OR      BP,BP                   ;If number mode flag not set then
  1329.                JZ      NEXT_PARAM              ;semi-colon not prefaced with no.
  1330.                MOV     AL,DL                   ;Else, store number.
  1331.                STOSB
  1332.                JMP     SHORT NEXT_NUM          ;Reset number carrying registers.
  1333.  
  1334. QUOTE_MODE:    CMP     AL,AH                   ;Is current char a string ending
  1335.                JZ      NEXT_STRING             ; quote?  If yes, exit quote mode
  1336.                STOSB                           ;Else, store char as literal.
  1337.                JMP     SHORT NEXT_PARAM
  1338.  
  1339. ;----------------------------------------------------------------------------;
  1340. ; Remove duplicate assignments if removal leaves room for new assignment.    ;
  1341. ; If no duplicate and room, add new assignment, else flush buffer to screen. ;
  1342. ;----------------------------------------------------------------------------;
  1343.  
  1344. PARSE_END:     OR      BP,BP                   ;Was last parameter a number?
  1345.                JZ      CK_LENGTH               ;If no, skip.
  1346.                MOV     AL,DL                   ;Else, store the last number.
  1347.                STOSB
  1348. CK_LENGTH:     SUB     DI,OFFSET PARSE_BUFFER - 2   ;Calculate string length
  1349.                MOV     AX,DI                        ; including word for length.
  1350.                MOV     BX,WORD PTR PARSE_BUFFER     ;BL=new first ASCII; BH=2nd.
  1351.                MOV     CX,5                         ;String length has to be at
  1352.                OR      BL,BL                   ;least word + 2 for old + new = 5
  1353.                JZ      CK_LEGAL                ; for extended key reassignment.
  1354.                DEC     CX                      ;And word + 1 for old + new = 4
  1355. CK_LEGAL:      CMP     AX,CX                   ; for regular ASCII reassignment.
  1356.                JB      ASSIGN_FLUSH            ;If not, illegal; flush buffer.
  1357.                MOV     BP,BUFFER_END           ;BP to carry buffer end pointer.
  1358.                CALL    CK_MATCH                ;Is char already reassigned?
  1359.                JC      CK_ROOM                 ;If no, check room for new.
  1360.  
  1361. CK_REMOVE:     MOV     CX,DX                   ;REASSIGN_END - string end
  1362.                SUB     CX,SI                   ; = bytes to move.
  1363.                JZ      CK_ROOM                 ;If zero, last string.
  1364.                SUB     DX,[DI]                 ;Is REASSIGN_END - old string
  1365.                ADD     DX,AX                   ; + new string >
  1366.                CMP     DX,BP                   ; BUFFER_END?
  1367.                JA      ASSIGN_FLUSH            ;If yes, flush buffer to screen.
  1368.                REP     MOVSB                   ;Else, move them down in buffer.
  1369.                JMP     SHORT STORE_NEW
  1370.  
  1371. CK_ROOM:       ADD     DX,AX                   ;New string + current strings.
  1372.                CMP     DX,BP                   ;Greater than buffer size?
  1373.                JA      ASSIGN_FLUSH            ;If yes, flush new string.
  1374. STORE_NEW:     MOV     SI,OFFSET PARSE_BUFFER  ;Else, room for new string.
  1375.                STOSW                           ;Store string length first.
  1376.                MOV     CX,AX                   ;Adjust counter.
  1377.                DEC     CX
  1378.                DEC     CX
  1379.                REP     MOVSB                   ;Store the actual string.
  1380.                MOV     REASSIGN_END,DI         ;Store new string end.
  1381.                RET
  1382.  
  1383. ASSIGN_FLUSH:  MOV     AL,"p"                  ;If buffer full, flush string
  1384.                JMP     FLUSH_BUFFER            ; including ending "p" command.
  1385.  
  1386. ;------------------------------------------------------------------------------;
  1387. ; INPUT:  BL = first ASCII code to match; BH = extended if BL = 0              ;
  1388. ; OUTPUT: CY = 1 if no match found; CY = 0 if match found.                     ;
  1389. ;         DI points to string length of match; DI+2 points to start of string. ;
  1390. ;         SI = end of string; DX = REASSIGN_END; BP = BUFFER_END               ;
  1391. ;------------------------------------------------------------------------------;
  1392.  
  1393. CK_MATCH:      MOV     DX,REASSIGN_END                ;Current strings end.
  1394.                MOV     SI,OFFSET REASSIGNMENT_BUFFER  ;Point to buffer.
  1395. NEXT_MATCH:    MOV     DI,SI                          ;Current record.
  1396.                CMP     DI,DX                   ;End of strings?
  1397.                JAE     NO_MATCH                ;If yes, no match.
  1398.                MOV     CX,[DI+2]               ;CL=current first ASCII; CH=2nd
  1399.                ADD     SI,[DI]                 ;Point to next record.
  1400.                CMP     BL,CL                   ;First characters match?
  1401.                JNZ     NEXT_MATCH              ;If no, check next record.
  1402.                OR      BL,BL                   ;Extended code? ie zero.
  1403.                JNZ     MATCH                   ;If no, then match.
  1404.                CMP     BH,CH                   ;Else, check second code.
  1405.                JNZ     NEXT_MATCH              ;If not same, no match.
  1406. MATCH:         CLC                             ;Else return with CY = 0
  1407.                RET
  1408.  
  1409. NO_MATCH:      STC                             ;No match; CY = 1.
  1410.                RET
  1411.  
  1412. ;----------------------------------------------------------------------;
  1413. ; Buffer area will write over disposable data and initialization code. ;
  1414. ;----------------------------------------------------------------------;
  1415.  
  1416. ESC_BUFFER            =       $
  1417. NUMBER_BUFFER         =       ESC_BUFFER + ESC_BUFFER_SIZE
  1418. PARSE_BUFFER          =       NUMBER_BUFFER
  1419. DEVICE_STATUS_BUFFER  =       PARSE_BUFFER + ESC_BUFFER_SIZE
  1420. DEVICE_STATUS_SIZE    =       11
  1421. REASSIGNMENT_BUFFER   =       DEVICE_STATUS_BUFFER + DEVICE_STATUS_SIZE
  1422.  
  1423. ;              DISPOSABLE DATA
  1424. ;              ---------------
  1425.  
  1426. SYNTAX         LABEL   BYTE
  1427. DB      "Syntax:  ANSI [FAST | SLOW][ON | OFF][KON | KOFF][PON | POFF]",CR,LF ;:
  1428. DB      "              [/B nnn][/C][/Q][/U][/T][/S][P n]",CR,LF ;. ;@       ;:
  1429. DB      "FAST     = direct screen writes; default",CR,LF                    ;:
  1430. DB      "SLOW     = screen writes via BIOS",CR,LF                           ;:
  1431. DB      "ON/OFF   = active/inactive; default is ON",CR,LF                   ;:
  1432. DB      "KON/KOFF = active/inactive reassignments; default is ON",CR,LF     ;:
  1433. DB      "PON/POFF = active/inactive NEW reassignments; default is ON",CR,LF ;:
  1434. DB      "nnn = buffer size in bytes (0 - 60K) reserved for key reassignment; "
  1435. DB      "default 200",CR,LF
  1436. DB      "/Q  = Quiet, no output when executed",CR,LF                        ;:
  1437. DB      "/U  = Uninstall",CR,LF                                             ;:
  1438. DB      "/T  = Load stats from ANSICOM.SYS",CR,LF                           ;@
  1439. DB      "/Pn = Protect n lines from scrolling at top"                       ;.
  1440. CR_LF   DB     CR,LF,LF,"$"
  1441.  
  1442. STATUS_MSG     DB      "Status: $"
  1443. BUFFER_MSG     DB      CR,LF,"Buffer size: $"
  1444. BYTES_FREE     DB      CR,LF,"Bytes free:  $"
  1445. ANSI_SYS_MSG   DB      "ANSI.SYS is installed so "
  1446. NOT_INSTALLED  DB      "ANSI.COM not installed",CR,LF,"$"
  1447. CON            DB      "CON"
  1448. CON_OFFSET     EQU     10
  1449. QUIET          DB      0                             ;| Quiet Mode
  1450. SYNTAX_FLAG    DB      0                             ;; Syntax Display Flag
  1451.  
  1452. SIZE_MSG       DB      "Uninstall to change buffer size",CR,LF,LF,"$"
  1453. UNLOAD_MSG     DB      "ANSI can't be uninstalled",CR,LF
  1454.                DB      "Uninstall resident programs in reverse order",CR,LF,"$"
  1455. NOT_ENOUGH     DB      "Not enough memory",CR,LF,"$"
  1456. ALLOCATE_MSG   DB      "Memory allocation error",CR,LF,BELL,"$"
  1457. INSTALL_MSG    DB      "Installed",CR,LF,"$"
  1458. UNINSTALL_MSG  DB      "Uninstalled",CR,LF,"$"
  1459. NO_FILE_MSG    DB      "ANSICOM.SYS not found",CR,LF,"$"                ;@
  1460. FILE_ERROR_MSG DB      "Error reading ANSICOM.SYS",CR,LF,"$"            ;@
  1461. FILE_NAME      DB      "ANSICOM.SYS",0                                  ;@
  1462.  
  1463. ;--------------------------------------------------------------------;
  1464. ; Search memory for a copy of our code, to see if already installed. ;
  1465. ;--------------------------------------------------------------------;
  1466.  
  1467. INITIALIZE     PROC    NEAR
  1468.                CLD                             ;All string operations forward.
  1469.                MOV     BX,OFFSET START         ;Point to start of code.
  1470.                NOT     BYTE PTR [BX]           ;Change a byte so no false match.
  1471.                XOR     DX,DX                   ;Start at segment zero.
  1472.                MOV     AX,CS                   ;Store our segment in AX.
  1473. NEXT_PARAG:    INC     DX                      ;Next paragraph.
  1474.                MOV     ES,DX
  1475.                CMP     DX,AX                   ;Is it our segment?
  1476.                JZ      ANNOUNCE                ;If yes, search is done.
  1477.                MOV     SI,BX                   ;Else, point to our signature.
  1478.                MOV     DI,BX                   ; and offset of possible match.
  1479.                MOV     CX,16                   ;Check 16 bytes for match.
  1480.                REP     CMPSB
  1481.                JNZ     NEXT_PARAG              ;If no match, keep looking.
  1482.  
  1483. ;------------------------------------------------;
  1484.  
  1485. ANNOUNCE:                                      ;|
  1486.                MOV     SI,81H                  ;Point to command line.
  1487. NEXT_CAP:      LODSB                           ;Capitalize parameters.
  1488.                CMP     AL,CR
  1489.                JZ      PARSE
  1490.                CMP     AL,"a"
  1491.                JB      NEXT_CAP
  1492.                CMP     AL,"z"
  1493.                JA      NEXT_CAP
  1494.                AND     BYTE PTR [SI - 1],5FH
  1495.                JMP     SHORT NEXT_CAP
  1496.  
  1497. ;------------------------------------------------;
  1498.  
  1499. PARSE:         MOV     SI,81H                  ;Point to command line again.
  1500. NEXT_PARA:     XOR     AX,AX                   ;Position in status parameters.
  1501.                MOV     BX,4                    ;Status parameters each 4 bytes.
  1502. NEXT_STATUS:   MOV     DI,OFFSET PARAMETERS    ;Point to "OFF ON  SLOWFAST"
  1503.                ADD     DI,AX                   ;Point to next parameter.
  1504.                ADD     AX,BX
  1505.                CMP     AX,LAST_PARAMETER       ;:Check all 8 possible statuses
  1506.                JA      CK_SWITCHES
  1507.                PUSH    SI                      ;Save command line pointer.
  1508.                MOV     CX,2                    ;Check first two bytes for match.
  1509.                CMP     AX,20                   ;: 3 Bytes for
  1510.                JB      Len_OK                  ;:   KON | KOFF | PON | POFF
  1511.                INC     CX                      ;:
  1512. Len_OK:                                        ;:
  1513.                REP     CMPSB
  1514.                POP     SI                      ;Recover command line pointer.
  1515.                JNZ     NEXT_STATUS
  1516.  
  1517.                DIV     BL                      ;If match, divide offset by four.
  1518. ;:
  1519. ;:  Next 12 lines of routine changed
  1520. ;:
  1521. ;:             MOV     CL,1                    ;Set a bit to match offset.
  1522. ;:NEXT_SHIFT:  SHL     CL,1
  1523. ;:             DEC     AL
  1524. ;:             JNZ     NEXT_SHIFT
  1525. ;:             SHR     CL,1                    ;Adjust.
  1526. ;:             MOV     AH,STATUS_MASK          ;Retrieve appropriate ON/OFF
  1527. ;:             CMP     CL,ON                   ; or FAST/SLOW mask.
  1528. ;:             JBE     ADD_STATUS
  1529. ;:             ROL     AH,1
  1530. ;:             ROL     AH,1
  1531. ;:
  1532. ;:ADD_STATUS:  AND     ES:STATUS,AH            ;Mask off old status.
  1533. ;:             OR      ES:STATUS,CL            ;Add new status.
  1534. ;:
  1535.                MOV     CL,AL                   ;:place count in CL (1 - 8)
  1536.                MOV     AX,STATUS_MASK          ;:Retrieve appropriate ON/OFF
  1537.                                                ;:FAST|SLOW|KON|KOFF|PON|POFF
  1538.                DEC     CL                      ;:Make 1 - 8 into 0 - 7
  1539.                JZ      Skip_1                  ;:In position already if zero
  1540.                SHL     AL,CL                   ;:Shift bit into position
  1541. Skip_1:        SHR     CL,1                    ;:divide count by 2
  1542.                JZ      Skip_2                  ;:
  1543.                ROL     AH,CL                   ;:Shift Mask into position
  1544.                ROL     AH,CL                   ;:
  1545. Skip_2:                                        ;:
  1546.  
  1547.                AND     ES:STATUS,AH            ;Mask off old status.
  1548.                OR      ES:STATUS,AL            ;:Add new status.
  1549.                INC     SI                      ;Bump command line pointer.
  1550.                INC     SI
  1551.  
  1552. CK_SWITCHES:   LODSB                           ;Get a byte.
  1553.                CMP     AL,CR                   ;Is it carriage return?
  1554.                JE      INSTALL                 ;If yes, done here.
  1555.                CMP     AL,"?"                  ;;Request for Syntax?
  1556.                JNE     CK_SW                   ;; No -
  1557.                MOV     BYTE PTR SYNTAX_FLAG, 1 ;; Yes-Show Syntax
  1558. CK_SW:         CMP     AL,"/"                  ;;Is there a switch character?
  1559.                JNE     NEXT_PARA               ;;If no, keep looking.
  1560. GOT_SWITCH:    LODSB                           ;;Else, get the switch character.
  1561.                CMP     AL,"B"                  ;Is it "B" ?
  1562.                JNZ     CK_C                    ;If no, check "C".
  1563.                CALL    CK_INSTALLED            ;Else, see if already installed.
  1564.                JZ      GET_SIZE                ;If no, get buffer request size.
  1565.                MOV     DX,OFFSET SIZE_MSG      ;Else, display error message.
  1566.                CALL    PRINT_STRING
  1567. NEXT_PARA2:    JMP     SHORT NEXT_PARA
  1568. GET_SIZE:      CALL    DECIMAL_INPUT           ;Get number parameter.
  1569.                CMP     BX,REASSIGNMENT_MAX     ;If greater than maximum, use
  1570.                JBE     STORE_BUFFER            ; maximum, else use requested
  1571.                MOV     BX,REASSIGNMENT_MAX     ; size.
  1572. STORE_BUFFER:  MOV     REASSIGNMENT_SIZE,BX
  1573.                ADD     BX,OFFSET REASSIGNMENT_BUFFER  ;Calculate end of buffer.
  1574.                MOV     BUFFER_END,BX
  1575.                JMP     NEXT_PARA               ;;Too far for direct jump
  1576.  
  1577. CK_C:          CMP     AL,"C"                  ;Is it "C" ?
  1578.                JNZ     CK_S                    ;@ If not, check "S".
  1579.                MOV     ES:REASSIGN_END,OFFSET REASSIGNMENT_BUFFER  ;Clear buffer
  1580.                JMP     NEXT_PARA               ;Else, next parmater.
  1581. CK_S:          CMP     AL,"S"                  ;@ Is It "S" ?
  1582.                JNZ     CK_P                    ;. If not, check "P".
  1583.                CALL    LOAD_STATS              ;@ Yes, Load Stats
  1584.                JMP     NEXT_PARA2              ;@ Next parameter (indirect)
  1585. CK_P:          CMP     AL,"P"                  ;. Is it "P" ?
  1586.                JNZ     CK_Q                    ;|If not, check "Q".
  1587.                CALL    DECIMAL_INPUT           ;. Get number of lines
  1588.                MOV     ES:START_SCROLL,BL      ;. Store the value
  1589.                JMP     NEXT_PARA2              ;. Next parameter (indirect)
  1590. CK_Q:          CMP     AL,"Q"                  ;|See if Quiet Mode
  1591.                JNE     CK_U                    ;|If not, check "U".
  1592.                NOT     QUIET                   ;|If yes turn on Quiet
  1593.                JMP     NEXT_PARA               ;Else, next parmater.
  1594. CK_U:          CMP     AL,"U"                  ;Is it "U" ?
  1595.                JE      DO_U                    ;If yes, try to uninstall.
  1596.                CMP     AL,"T"                  ;; Test if Installed
  1597.                JE      DO_U
  1598.                MOV     BYTE PTR SYNTAX_FLAG, 1 ;; Syntax Error
  1599.                JMP     NEXT_PARA               ;Else, next parmater.
  1600.  
  1601. ;------------------------------------------------;
  1602.  
  1603. INSTALL:
  1604.                MOV     DX,OFFSET SIGNATURE     ;|Display our signature.
  1605.                CALL    PRINT_STRING            ;|
  1606.                CMP     BYTE PTR SYNTAX_FLAG,0  ;;Display Syntax?
  1607.                JE      SKIP_SYNTAX             ;;No
  1608.                MOV     DX,OFFSET SYNTAX        ;|Yes, Display syntax.
  1609.                CALL    PRINT_STRING            ;|
  1610. SKIP_SYNTAX:   CALL    STATUS_REPORT          ;;|Display status.
  1611.                CALL    CK_INSTALLED            ;Check if already installed.
  1612.                JZ      CK_AVAILABLE            ;If no, see if enough memory.
  1613. EXIT2:         XOR     AL,AL                   ;;Else, done.
  1614.                JMP     EXIT                    ;Exit with ERRORLEVEL = 0.
  1615.  
  1616. DO_U:          CALL    CK_INSTALLED            ;Else, see if installed.
  1617.                MOV     DX,OFFSET NOT_INSTALLED ;If no, exit with error message.
  1618.                JZ      LILLY_PAD               ;Too far for short jump.
  1619.                CMP     AL,"T"                  ;;Was it a test
  1620.                JE      EXIT2                   ;;Yes Too far for short jump.
  1621.                JMP     UNINSTALL               ;Else, uninstall.
  1622.  
  1623. ;--------------------------------;
  1624. ; This is the install procedure. ;
  1625. ;--------------------------------;
  1626.  
  1627. CK_AVAILABLE:  MOV     BP,OFFSET REASSIGNMENT_BUFFER   ;TSR ends at end
  1628.                ADD     BP,REASSIGNMENT_SIZE            ; of reassignment buffer.
  1629.                ADD     BP,15                           ;Round up.
  1630.                CMP     BP,DS:[6]               ;Buffer > PSP bytes in segment?
  1631.                MOV     DX,OFFSET NOT_ENOUGH    ;If yes, exit without installing
  1632.                JBE     CK_ANSI                 ;@
  1633.                JMP     MSG_EXIT                ;@with message
  1634. CK_ANSI:       MOV     AX,3529H                ;@Get undocumented INT 29 vector.
  1635.                INT     21H
  1636.                MOV     SI,OFFSET CON           ;Does it point to ANSI.SYS?
  1637.                MOV     DI,CON_OFFSET           ;Check by looking for "CON"
  1638.                MOV     CX,3                    ; as device name.
  1639.                REP     CMPSB
  1640.                MOV     DX,OFFSET ANSI_SYS_MSG  ;Exit with error message if
  1641. LILLY_PAD:     JZ      MSG_EXIT                ;ANSI.SYS loaded.
  1642.  
  1643.                MOV     OLD_INT_29[0],BX        ;Else save old interrupt.
  1644.                MOV     OLD_INT_29[2],ES
  1645.                MOV     DX,OFFSET ANSI_INT_29   ;Install new interrupt.
  1646.                MOV     AX,2529H
  1647.                INT     21H
  1648.                MOV     AX,3516H                ;Get INT 16 vector.
  1649.                INT     21H
  1650.                MOV     OLD_INT_16[0],BX        ;Save old interrupt.
  1651.                MOV     OLD_INT_16[2],ES
  1652.                MOV     DX,OFFSET ANSI_INT_16   ;Install new interrupt.
  1653.                MOV     AX,2516H
  1654.                INT     21H
  1655.                MOV     AX,3521H                ;Get DOS 21h interrupt.
  1656.                INT     21H
  1657.                MOV     OLD_INT_21[0],BX        ;Save old interrupt.
  1658.                MOV     OLD_INT_21[2],ES
  1659.                MOV     DX,OFFSET ANSI_INT_21   ;Install new interrupt.
  1660.                MOV     AX,2521H
  1661.                INT     21H
  1662.                MOV     AX,3508H                ;@ Get INT 08 vector.
  1663.                INT     21H                     ;@
  1664.                MOV     OLD_INT_08[0],BX        ;@ Save old interrupt.
  1665.                MOV     OLD_INT_08[2],ES        ;@
  1666.                MOV     DX,OFFSET ANSI_INT_08   ;@ Install new interrupt.
  1667.                MOV     AX,2508H                ;@
  1668.                INT     21H                     ;@
  1669.  
  1670.                MOV     AX,DS:[2CH]             ;Get environment segment.
  1671.                MOV     ES,AX
  1672.                MOV     AH,49H                  ;Free up environment.
  1673.                INT     21H
  1674.  
  1675.                MOV     DX,OFFSET INSTALL_MSG   ;Display install message.
  1676.                CALL    PRINT_STRING
  1677.                CALL    FLUSH_END               ;Setup the number buffer.
  1678.                MOV     DX,BP                   ;Retrieve resident byte request.
  1679.                MOV     CL,4
  1680.                SHR     DX,CL                   ;Convert to paragraphs.
  1681.                MOV     AX,3100H                ;Return error code of zero.
  1682.                INT     21H                     ;Terminate but stay resident.
  1683.  
  1684. ;-------------------------------------------------------------------;
  1685. ; Exit.  Return ERRORLEVEL code 0 if successful, 1 if unsuccessful. ;
  1686. ;-------------------------------------------------------------------;
  1687.  
  1688. MSG_EXIT:      CALL    PRINT_STRING
  1689. ERROR_EXIT:    MOV     AL,1                    ;ERRORLEVEL = 1.
  1690. EXIT:          MOV     AH,4CH                  ;Terminate.
  1691.                INT     21H
  1692.  
  1693. ;---------------------------------------------------;
  1694. ; This subroutine uninstalls the resident ANSI.COM. ;
  1695. ;---------------------------------------------------;
  1696.  
  1697. UNINSTALL:     AND     ES:STATUS,NOT ON        ;Turn OFF ANSI, just in case
  1698.                OR      ES:STATUS,OFF           ; can't uninstall.
  1699.                MOV     CX,ES                   ;Save segment in CX.
  1700.                MOV     AX,3529H                ;Get interrupt 29h.
  1701.                INT     21H
  1702.                CMP     BX,OFFSET ANSI_INT_29   ;Has it been hooked by another?
  1703.                JNZ     UNINSTALL_ERR2          ;@If yes, exit with error message.
  1704.                MOV     BX,ES
  1705.                CMP     BX,CX                   ;Is the segment vector same?
  1706.                JNZ     UNINSTALL_ERR2          ;@If no, exit with error message.
  1707.  
  1708.                MOV     AX,3508H                ;@Get interrupt 08h.
  1709.                INT     21H                     ;@
  1710.                CMP     BX,OFFSET ANSI_INT_08   ;@Has it been hooked by another?
  1711.                JNZ     UNINSTALL_ERR           ;@If yes, exit with error message.
  1712.                MOV     BX,ES                   ;@
  1713.                CMP     BX,CX                   ;@Is the segment vector same?
  1714. UNINSTALL_ERR2:JNZ     UNINSTALL_ERR           ;@If no, exit with error message.
  1715.  
  1716.                MOV     AX,3516H                ;Get interrupt 16h.
  1717.                INT     21H
  1718.                CMP     BX,OFFSET ANSI_INT_16   ;Has it been hooked by another?
  1719.                JNZ     UNINSTALL_ERR           ;If yes, exit with error message.
  1720.                MOV     BX,ES
  1721.                CMP     BX,CX                   ;Is the segment vector same?
  1722.                JNZ     UNINSTALL_ERR           ;If no, exit with error message.
  1723.  
  1724.                MOV     AX,3521H                ;Get interrupt 21h.
  1725.                INT     21H
  1726.                CMP     BX,OFFSET ANSI_INT_21   ;Has it been hooked by another?
  1727.                JNZ     UNINSTALL_ERR           ;If yes, exit with error message.
  1728.                MOV     BX,ES
  1729.                CMP     BX,CX                   ;Is the segment vector same?
  1730.                JNZ     UNINSTALL_ERR           ;If no, exit with error message.
  1731.  
  1732.                MOV     AH,49H                  ;Return memory to system pool.
  1733.                INT     21H
  1734.                MOV     DX,OFFSET ALLOCATE_MSG
  1735.                JC      MSG_EXIT                ;Display message if problem.
  1736.  
  1737.                MOV     DX,ES:OLD_INT_29[0]     ;Restore old INT 29.
  1738.                MOV     DS,ES:OLD_INT_29[2]
  1739.                MOV     AX,2529H
  1740.                INT     21H
  1741.                MOV     DX,ES:OLD_INT_08[0]     ;@Restore old INT 08.
  1742.                MOV     DS,ES:OLD_INT_08[2]     ;@
  1743.                MOV     AX,2508H                ;@
  1744.                INT     21H                     ;@
  1745.                MOV     DX,ES:OLD_INT_16[0]     ;Restore old INT 16.
  1746.                MOV     DS,ES:OLD_INT_16[2]
  1747.                MOV     AX,2516H
  1748.                INT     21H
  1749.                MOV     DX,ES:OLD_INT_21[0]     ;Restore old INT 21.
  1750.                MOV     DS,ES:OLD_INT_21[2]
  1751.                MOV     AX,2521H
  1752.                INT     21H
  1753.  
  1754.                PUSH    CS
  1755.                POP     DS                      ;Point to our data.
  1756.                MOV     DX,OFFSET UNINSTALL_MSG ;Display uninstall message.
  1757.                CALL    PRINT_STRING
  1758.                OR      AL,AL                   ;Exit with ERRORLEVEL = 0.
  1759.                JMP     EXIT
  1760.  
  1761. UNINSTALL_ERR: MOV     ES,CX                   ;If error, display OFF status.
  1762.                CALL    STATUS_REPORT
  1763.                MOV     DX,OFFSET UNLOAD_MSG    ;And exit with error message.
  1764.                JMP     MSG_EXIT
  1765. INITIALIZE     ENDP
  1766.  
  1767. ;--------------------------------------------------;
  1768. ; INPUT:  SI points to parameter start.            ;
  1769. ; OUTPUT: SI points to parameter end; BX = number. ;
  1770. ;--------------------------------------------------;
  1771.  
  1772. DECIMAL_INPUT  PROC    NEAR
  1773.                XOR     BX,BX                   ;Start with zero as number.
  1774. NEXT_DECIMAL:  LODSB                           ;Get a character.
  1775.                CMP     AL,CR                   ;Carriage return?
  1776.                JZ      ADJUST_DEC              ;If yes, done here.
  1777.                CMP     AL,"/"                  ;Forward slash?
  1778.                JZ      ADJUST_DEC              ;If yes, done here.
  1779.                SUB     AL,"0"                  ;ASCII to binary.
  1780.                JC      NEXT_DECIMAL            ;If not between 0 and 9, skip.
  1781.                CMP     AL,9
  1782.                JA      NEXT_DECIMAL
  1783.                CBW                             ;Convert byte to word.
  1784.                XCHG    AX,BX                   ;Swap old and new number.
  1785.                MOV     CX,10                   ;Shift to left by multiplying
  1786.                MUL     CX                      ; last entry by ten.
  1787.                JC      DECIMAL_ERROR           ;If carry, too big.
  1788.                ADD     BX,AX                   ;Add new number and store in BX.
  1789.                JNC     NEXT_DECIMAL            ;If not carry, next number.
  1790. DECIMAL_ERROR: MOV     BX,-1                   ;Else, too big; return -1.
  1791.  
  1792. ADJUST_DEC:    DEC     SI                      ;Adjust pointer.
  1793.                RET
  1794. DECIMAL_INPUT  ENDP
  1795.  
  1796. ;-------------------------------------------------------;
  1797. ; OUTPUT: ZR = 1 if not installed; ZR = 0 if installed. ;
  1798. ;-------------------------------------------------------;
  1799.  
  1800. CK_INSTALLED:  PUSH    AX                      ;;
  1801.                MOV     AX,ES
  1802.                MOV     BX,CS
  1803.                CMP     AX,BX                   ;Compare segments.
  1804.                POP     AX                      ;;
  1805.                RET
  1806.  
  1807. ;------------------------------------------------;
  1808.  
  1809. STATUS_REPORT: MOV     DX,OFFSET STATUS_MSG
  1810.                CALL    PRINT_STRING            ;Display "Status: ".
  1811.                MOV     BL,ES:STATUS
  1812.                MOV     BH,1
  1813. NEXT_REPORT:   TEST    BL,BH
  1814.                JZ      LOOP_STATUS
  1815.  
  1816.                MOV     DL,BH
  1817. ;:
  1818. ;: Next 9 Lines changed
  1819. ;:
  1820. ;:             MOV     AX,-1
  1821. ;:NEXT_BIT:    INC     AX
  1822. ;:             SHR     DL,1
  1823. ;:             JNC     NEXT_BIT
  1824. ;:             SHL     AX,1
  1825. ;:             SHL     AX,1
  1826. ;:             MOV     SI,OFFSET PARAMETERS    ;Display appropriate ON or OFF,
  1827. ;:             ADD     SI,AX                   ; SLOW or FAST.
  1828. ;:             MOV     CX,4
  1829. ;:
  1830.                MOV     SI,OFFSET PARAMETERS    ;:Display appropriate ON or OFF,
  1831.                                                ;: SLOW|FAST.  KON|KOFF|PON|POFF
  1832.                MOV     CX,4                    ;:Each four characters long
  1833. NEXT_BIT:      SHR     DL,1                    ;:Is this our Word?
  1834.                JC      REPORT                  ;:Yes - Print it
  1835.                ADD     SI,CX                   ;:No  - Skip over it
  1836.                JMP     NEXT_BIT                ;:test the next bit
  1837. REPORT:        LODSB
  1838.                CALL    PRINT_CHAR
  1839.                LOOP    REPORT
  1840.                MOV     AL, " "                 ;: Space words
  1841.                CALL    PRINT_CHAR              ;:
  1842.  
  1843. LOOP_STATUS:   SHL     BH,1
  1844.                JNC     NEXT_REPORT             ;: Check all 8 bits
  1845.                                                ;:
  1846.                MOV     DX,OFFSET BUFFER_MSG    ;Display "Buffer size: ".
  1847.                CALL    PRINT_STRING
  1848.                MOV     AX,ES:REASSIGNMENT_SIZE
  1849.                PUSH    AX
  1850.                XOR     BP,BP
  1851.                CALL    DECIMAL_OUT             ;Display the size.
  1852.                MOV     DX,OFFSET BYTES_FREE    ;Display "Bytes free: ".
  1853.                CALL    PRINT_STRING
  1854.                POP     AX
  1855.                ADD     AX,OFFSET REASSIGNMENT_BUFFER
  1856.                SUB     AX,ES:REASSIGN_END
  1857.                CALL    DECIMAL_OUT             ;Display the bytes free.
  1858.                MOV     DX,OFFSET CR_LF
  1859.                CALL    PRINT_STRING
  1860.                RET
  1861.  
  1862. ;------------------------------------------------;
  1863.  
  1864. PRINT_CHAR:    MOV     DL,AL
  1865.                MOV     AH,2                    ;Print character via DOS.
  1866.                OR      AL,AL                   ;:Skip NULLs
  1867.                JNZ     SHORT DOS_INT           ;:
  1868.                RET                             ;:
  1869.  
  1870. PRINT_STRING:  MOV     AH,9                    ;Print string via DOS.
  1871. DOS_INT:       CMP     QUIET,0                 ;|Do we suppress output
  1872.                JNE     NO_PRINT                ;|Yes
  1873.                INT     21H                     ;|No
  1874. NO_PRINT:                                      ;|
  1875.                RET
  1876.  
  1877. LOAD_STATS:    MOV    DX,OFFSET FILE_NAME      ;@ Stat filename
  1878.                MOV    AX,3D00H                 ;@ Open File
  1879.                INT    21H                      ;@ DOS Interupt
  1880.                MOV    DX,OFFSET NO_FILE_MSG    ;@ Assume no file
  1881.                JNC    OPEN_OK                  ;@ Ok, So far
  1882. MSG_EXIT2:     JMP    MSG_EXIT                 ;@ No file found probably
  1883. OPEN_OK:       MOV    BX,AX                    ;@ This is our Handle number
  1884.                PUSH   DS                       ;@ Save DS
  1885.                PUSH   ES                       ;@ Set ES to DS
  1886.                POP    DS                       ;@
  1887.                MOV    DX, OFFSET SUB_LIST      ;@ Point to the Sub_List
  1888.                MOV    CX, SUB_LENGTH           ;@ Get the Length ot the List
  1889.                MOV    AH,3FH                   ;@ Read from Handle
  1890.                INT    21H                      ;@ DOS Interupt
  1891.                POP    DS                       ;@ Restore DS
  1892.                PUSHF                           ;@ Save results
  1893.                PUSH   AX                       ;@
  1894.                MOV    AH,3EH                   ;@ Close Handle
  1895.                INT    21H                      ;@ DOS Interupt
  1896.                POP    AX                       ;@ Restore results
  1897.                POPF                            ;@
  1898.                MOV    DX,OFFSET FILE_ERROR_MSG ;@ Assume an error occured
  1899.                JC     MSG_EXIT2                ;@ Yep, it did
  1900.                XCHG   AX,CX                    ;@ Swap Bytes Read
  1901.                JCXZ   MSG_EXIT2                ;@ Something went wrong
  1902.                CMP    AX,CX                    ;@ Did we read the full amount
  1903.                JNE    MSG_EXIT2                ;@ No
  1904.                RET                             ;@ All went well!
  1905.  
  1906. _TEXT          ENDS
  1907.                END     START
  1908.